Exemple #1
0
 def create_symbol_popup(self, update=False):
     if self.typed_expr or self.decl:
         popup_parts = [
             SUBHASK_STYLES.gen_style(
                 self.view.settings().get('color_scheme'))
         ]
         if self.typed_expr:
             popup_parts.append(
                 u'<p><span class="function">{0}</span>{1}</p>'.format(
                     self.typed_expr.substr(self.view),
                     symbols.format_type(
                         UnicodeOpers.use_unicode_operators(
                             u' :: {0}'.format(self.typed_expr.typename)))))
         if self.decl:
             popup_msg = [u'<a href="import:{0}">Add import</a>'.format(html.escape(self.decl.name))] \
                         if self.suggest_import \
                         else []
             popup_parts.append(self.decl.popup(popup_msg))
         popup_text = u''.join(popup_parts)
         if update and self.view.is_popup_visible():
             self.view.update_popup(popup_text)
         else:
             self.view.show_popup(popup_text,
                                  sublime.HIDE_ON_MOUSE_MOVE_AWAY,
                                  self.point, 600, 600, self.on_navigate,
                                  self.on_hide)
Exemple #2
0
    def show_types(self, types):
        if not types:
            Common.show_status_message("Can't infer type", False)
            return

        types = sorted(filter(
            lambda t: t.region(self.view).contains(self.view.sel()[0]), types),
                       key=lambda t: t.region(self.view).size())
        self.output_view = Common.output_panel(self.view.window(),
                                               '',
                                               panel_name=TYPES_PANEL_NAME,
                                               syntax='Haskell-SublimeHaskell',
                                               panel_display=False)

        regions = []
        for typ in types:
            Common.output_text(self.output_view,
                               '{0}\n'.format(typ.show(self.view)),
                               clear=False)
            regions.append(
                sublime.Region(
                    self.output_view.size() - 1 -
                    len(UnicodeOpers.use_unicode_operators(typ.typename)),
                    self.output_view.size() - 1))
        self.output_view.add_regions('types', regions, 'comment', '',
                                     sublime.DRAW_OUTLINED)
        Common.show_panel(self.view.window(), panel_name=TYPES_PANEL_NAME)
Exemple #3
0
    def run(self, edit):
        selections = list(self.view.sel())

        if not self.is_infos_valid(selections):
            SublimeHaskellExpandSelectionExpression.Infos = [
                ExpandSelectionInfo(self.view, s) for s in selections
            ]

        if not self.is_infos_valid(selections):
            Common.show_status_message(
                'Unable to retrieve expand selection info', False)
            return

        selinfo = [i.expand() for i in self.Infos]
        self.view.sel().clear()
        self.view.sel().add_all([sel.region for sel in selinfo])

        Common.output_panel(
            self.view.window(),
            '\n'.join([
                UnicodeOpers.use_unicode_operators(sel.typename)
                for sel in selinfo
            ]),
            panel_name='sublime_haskell_expand_selection_expression',
            syntax='Haskell-SublimeHaskell')
Exemple #4
0
    def create_symbol_popup(self, typed_expr, decl, suggest_import):
        if typed_expr or decl:
            popup_parts = [
                self.STYLES.gen_style(self.view.settings().get('color_scheme'))
            ]
            if typed_expr:
                popup_parts.append(
                    u'<p><span class="function">{0}</span>{1}</p>'.format(
                        typed_expr.substr(self.view),
                        symbols.format_type(
                            UnicodeOpers.use_unicode_operators(
                                ' :: {0}'.format(typed_expr.typename)))))
            if decl:
                popup_msg = [u'<a href="import:{0}">Add import</a>'.format(urllib.parse.quote_plus(decl.name))] \
                            if suggest_import else []
                popup_parts.append(decl.popup(popup_msg))

            popup_text = u''.join(popup_parts)
            if not self.view.is_popup_visible():
                self.view.show_popup(popup_text,
                                     sublime.HIDE_ON_MOUSE_MOVE_AWAY,
                                     self.point, 600, 600, self.on_navigate,
                                     self.on_hide)
            else:
                self.view.update_popup(popup_text)
    def do_hover(self):
        if self.hover_zone == sublime.HOVER_TEXT:
            qsymbol = Common.get_qualified_symbol_at_point(self.view, self.point)
            ## print('hover: qualified symbol {0}'.format(qsymbol))
            module_word = qsymbol.module
            ident = qsymbol.name

            if module_word is not None and ident is None:
                # TODO: Any ideas for popup about module?
                pass
            elif ident is not None:
                whois_name = qsymbol.qualified_name()
                full_name = qsymbol.full_name()

                # Try get type of hovered symbol
                typed_expr = None
                if types.SourceHaskellTypeCache().has(self.filename):
                    typed_expr = self.get_type(types.SourceHaskellTypeCache().get(self.filename), whois_name)
                else:
                    project_name = Common.locate_cabal_project_from_view(self.view)[1]
                    point_rgn = sublime.Region(self.point, self.point)
                    typed_expr = self.get_type(types.get_type_view(self.view, project_name, point_rgn), whois_name)

                # Try whois
                suggest_import = False
                decl = Utils.head_of(BackendManager.active_backend().whois(whois_name, self.filename))
                if not decl:
                    suggest_import = True
                    decl = Utils.head_of(BackendManager.active_backend().lookup(full_name, self.filename))

                self.create_symbol_popup(typed_expr, decl, suggest_import)

        elif self.hover_zone == sublime.HOVER_GUTTER:
            errs = [err for err in ParseOutput.MARKER_MANAGER.marks_for_view(self.view) if err.region.start.line == self.line]
            if errs:
                popup_parts = [self.STYLES.gen_style(self.view.settings().get('color_scheme'))]
                for err in errs:
                    msg = UnicodeOpers.use_unicode_operators(symbols.escape_text(err.message))
                    # Decorate first word with style
                    decors = {
                        'Error': 'error',
                        'Warning': 'warning',
                        'Hint': 'hint'
                    }
                    for dec, dec_style in decors.items():
                        msg = msg.replace(dec, u'<span class="{0}">{1}</span>'.format(dec_style, dec))
                    popup_parts.append(u'<p>{0}</p>'.format(msg))
                    if err.correction is not None:
                        popup_parts.append(err.correction.popup())
                popup_text = u''.join(popup_parts)
                self.shown = True
                self.view.show_popup(popup_text, sublime.HIDE_ON_MOUSE_MOVE_AWAY, self.point, 600, 600,
                                     self.on_navigate, self.on_hide)
Exemple #6
0
    def do_hover(self):
        if self.hover_zone == sublime.HOVER_TEXT:
            qsymbol = Common.get_qualified_symbol_at_point(self.view, self.point)
            ## print('hover: qualified symbol {0}'.format(qsymbol))
            module_word = qsymbol.module
            ident = qsymbol.name

            if module_word is not None and ident is None:
                # TODO: Any ideas for popup about module?
                pass
            elif ident is not None:
                whois_name = qsymbol.qualified_name()
                full_name = qsymbol.full_name()

                # Try get type of hovered symbol
                typed_expr = None
                if types.SourceHaskellTypeCache().has(self.filename):
                    typed_expr = self.get_type(types.SourceHaskellTypeCache().get(self.filename), whois_name)
                else:
                    project_name = Common.locate_cabal_project_from_view(self.view)[1]
                    point_rgn = sublime.Region(self.point, self.point)
                    typed_expr = self.get_type(types.get_type_view(self.view, project_name, point_rgn), whois_name)

                # Try whois
                suggest_import = False
                decl = Utils.head_of(BackendManager.active_backend().whois(whois_name, self.filename))
                if not decl:
                    suggest_import = True
                    decl = Utils.head_of(BackendManager.active_backend().lookup(full_name, self.filename))

                self.create_symbol_popup(typed_expr, decl, suggest_import)

        elif self.hover_zone == sublime.HOVER_GUTTER:
            errs = [err for err in ParseOutput.errors_for_view(self.view) if err.region.start.line == self.line]
            if errs:
                popup_parts = [self.STYLES.gen_style(self.view.settings().get('color_scheme'))]
                for err in errs:
                    msg = UnicodeOpers.use_unicode_operators(symbols.escape_text(err.message))
                    # Decorate first word with style
                    decors = {
                        'Error': 'error',
                        'Warning': 'warning',
                        'Hint': 'hint'
                    }
                    for dec, dec_style in decors.items():
                        msg = msg.replace(dec, u'<span class="{0}">{1}</span>'.format(dec_style, dec))
                    popup_parts.append(u'<p>{0}</p>'.format(msg))
                    if err.correction is not None:
                        popup_parts.append(err.correction.popup())
                popup_text = u''.join(popup_parts)
                self.view.show_popup(popup_text, sublime.HIDE_ON_MOUSE_MOVE_AWAY, self.point, 600, 600,
                                     self.on_navigate, self.on_hide)
    def show_types(self, types):
        if not types:
            Common.sublime_status_message("Can't infer type")
            return

        self.types = types
        self.output_view = Common.output_panel(self.view.window(), '',
                                               panel_name=TYPES_PANEL_NAME,
                                               syntax='Haskell-SublimeHaskell',
                                               panel_display=False)
        regions = []
        for typ in self.types:
            Common.output_text(self.output_view, '{0}\n'.format(typ.show(self.view)), clear=False)
            regions.append(sublime.Region(self.output_view.size() - 1 - len(UnicodeOpers.use_unicode_operators(typ.typename)),
                                          self.output_view.size() - 1))
        self.output_view.add_regions('types', regions, 'comment', '', sublime.DRAW_OUTLINED)
        Common.show_panel(self.view.window(), panel_name=TYPES_PANEL_NAME)
    def run(self, edit, **_kwargs):
        selections = list(self.view.sel())

        if not self.is_infos_valid(selections):
            SublimeHaskellExpandSelectionExpression.Infos = [ExpandSelectionInfo(self.view, s) for s in selections]

        if not self.is_infos_valid(selections):
            Common.sublime_status_message('Unable to retrieve expand selection info')
            return

        selinfo = [i.expand() for i in self.Infos]
        self.view.sel().clear()
        self.view.sel().add_all([sel.region for sel in selinfo])

        Common.output_panel(self.view.window(),
                            '\n'.join([UnicodeOpers.use_unicode_operators(sel.typename) for sel in selinfo]),
                            panel_name='sublime_haskell_expand_selection_expression',
                            syntax='Haskell-SublimeHaskell')
    def create_symbol_popup(self, typed_expr, decl, suggest_import):
        if typed_expr or decl:
            popup_parts = [self.STYLES.gen_style(self.view.settings().get('color_scheme'))]
            if typed_expr:
                popup_parts.append(u'<p><span class="function">{0}</span>{1}</p>'.format(
                    typed_expr.substr(self.view),
                    symbols.format_type(UnicodeOpers.use_unicode_operators(' :: {0}'.format(typed_expr.typename)))))
            if decl:
                popup_msg = [u'<a href="import:{0}">Add import</a>'.format(urllib.parse.quote_plus(decl.name))] \
                            if suggest_import else []
                popup_parts.append(decl.popup(popup_msg))

            popup_text = u''.join(popup_parts)
            if not self.shown:
                self.shown = True
                self.view.show_popup(popup_text, sublime.HIDE_ON_MOUSE_MOVE_AWAY, self.point, 600, 600,
                                     self.on_navigate, self.on_hide)
            else:
                self.view.update_popup(popup_text)
Exemple #10
0
 def suggest(self):
     return (UnicodeOpers.use_unicode_operators(u'{0} {1}\t{2}'.format(
         self.name, ' '.join(self.args),
         self.imported_from_name())), self.name)
Exemple #11
0
 def suggest(self):
     return (UnicodeOpers.use_unicode_operators(u'{0} :: {1}\t{2}'.format(
         wrap_operator(self.name), self.type,
         self.imported_from_name())), self.name)
Exemple #12
0
 def wrapped(*args, use_unicode=None, **kwargs):
     if use_unicode is False:
         return wrap_fn(*args, **kwargs)
     return UnicodeOpers.use_unicode_operators(wrap_fn(*args, **kwargs),
                                               force=(use_unicode is True))
 def wrapped(*args, use_unicode=None, **kwargs):
     if use_unicode is False:
         return wrap_fn(*args, **kwargs)
     return UnicodeOpers.use_unicode_operators(wrap_fn(*args, **kwargs), force=(use_unicode is True))
 def suggest(self):
     return (UnicodeOpers.use_unicode_operators(u'{0} :: {1}\t{2}'.format(wrap_operator(self.name),
                                                                          self.type,
                                                                          self.imported_from_name())),
             self.name)
 def suggest(self):
     return (UnicodeOpers.use_unicode_operators(u'{0} {1}\t{2}'.format(self.name,
                                                                       ' '.join(self.args),
                                                                       self.imported_from_name())),
             self.name)
Exemple #16
0
 def suggest(self):
     return (UnicodeOpers.use_unicode_operators(u'{0}\t{1}'.format(
         wrap_operator(self.scope_name()),
         self.module.name)), self.scope_name())
Exemple #17
0
 def suggest(self):
     return (UnicodeOpers.use_unicode_operators(u'{0} {1}\t{2}'.format(
         self.scope_name(), ' '.join(self.args),
         self.module.name)), self.scope_name())
Exemple #18
0
    def create_symbol_popup(self,
                            typed_expr,
                            decl,
                            suggest_import,
                            usages=None):
        if typed_expr or decl:
            popup_parts = [
                self.STYLES.gen_style(self.view.settings().get('color_scheme'))
            ]
            if typed_expr:
                popup_parts.append(
                    u'<p><span class="function">{0}</span>{1}</p>'.format(
                        typed_expr.substr(self.view),
                        symbols.format_type(
                            UnicodeOpers.use_unicode_operators(
                                ' :: {0}'.format(typed_expr.typename)))))
            if decl:
                popup_msg = [u'<a href="import:{0}">Add import</a>'.format(urllib.parse.quote_plus(decl.name))] \
                            if suggest_import else []
                popup_parts.append(decl.popup(popup_msg))
            if usages is not None:
                source_symbol = decl.by_source()
                used_total = len(usages)
                used_here = len([
                    u for u in usages
                    if u.used_in.location.filename == self.filename
                ])
                used_defm = len([u for u in usages if u.internal_usage()])

                usages_ref = '<a href="usages:{0}:{1}">Usages</a>'.format(
                    self.line, self.column)

                if used_total == 0:
                    usages_tpl = 'Not used'
                elif not source_symbol:
                    usages_tpl = '{usages_ref}: {total} (<a href="select:{line}:{column}">{here} in this file</a>)'
                else:
                    if decl.module.location.filename == self.filename:
                        usages_tpl = '{usages_ref}: {total} (<a href="select:{line}:{column}">{here} in this file</a>)'
                    else:
                        usages_tpl = '{usages_ref}: {total} (<a href="select:{line}:{column}">{here} in this file</a>, {defm} in def file)'
                usages_msg = usages_tpl.format(
                    usages_ref=usages_ref,
                    total=used_total,
                    here=used_here,
                    defm=used_defm,
                    line=self.line,
                    column=self.column,
                )

                popup_parts.append(
                    u'<span class="comment">{0}</span>'.format(usages_msg))

            popup_text = u''.join(popup_parts)
            if not self.shown:
                self.shown = True
                self.view.show_popup(popup_text,
                                     sublime.HIDE_ON_MOUSE_MOVE_AWAY,
                                     self.point, 600, 600, self.on_navigate,
                                     self.on_hide)
            else:
                self.view.update_popup(popup_text)
Exemple #19
0
    def on_hover(self, view, point, hover_zone):
        if not Common.is_haskell_source(view):
            return

        self.view = view
        self.current_file_name = self.view.file_name()
        # If the column is needed: (line, column) = self.view.rowcol(point) [remove subscript]
        line = self.view.rowcol(point)[0]
        self.decl = None
        self.typed_expr = None

        if hover_zone == sublime.HOVER_TEXT:
            qsymbol = Common.get_qualified_symbol_at_point(self.view, point)
            module_word = qsymbol.module
            ident = qsymbol.name

            if ident is None and module_word:  # TODO: Any ideas for popup about module?
                pass

            if ident:
                self.whois_name = qsymbol.qualified_name()
                self.full_name = qsymbol.full_name()

                # Try get type of hovered symbol
                self.point = point
                self.typed_expr = None
                if types.FILE_TYPES.has(self.current_file_name):
                    self.typed_expr = self.get_type(
                        types.FILE_TYPES.get(self.current_file_name))
                else:
                    types.get_types(self.current_file_name, self.on_types)

                # Try whois
                self.suggest_import = False
                self.decl = Utils.head_of(
                    hsdev.client.whois(self.whois_name,
                                       self.current_file_name))

                if not self.decl:
                    self.suggest_import = True
                    self.decl = Utils.head_of(
                        hsdev.client.lookup(self.full_name,
                                            self.current_file_name))

                self.create_symbol_popup()

        elif hover_zone == sublime.HOVER_GUTTER:
            self.view = view
            self.current_file_name = self.view.file_name()
            errs = list(
                filter(lambda e: e.region.start.line == line,
                       parseoutput.errors_for_view(self.view)))
            if errs:
                popup_parts = [
                    SUBHASK_STYLES.gen_style(
                        self.view.settings().get('color_scheme'))
                ]
                for err in errs:
                    msg = UnicodeOpers.use_unicode_operators(
                        symbols.escape_text(err.message))
                    # Decorate first word with style
                    decors = {
                        'Error': 'error',
                        'Warning': 'warning',
                        'Hint': 'hint'
                    }
                    for dec, dec_style in decors.items():
                        msg = msg.replace(
                            dec, u'<span class="{0}">{1}</span>'.format(
                                dec_style, dec))
                    popup_parts.append(u'<p>{0}</p>'.format(msg))
                    if err.correction is not None:
                        popup_parts.append(err.correction.popup())
                popup_text = u''.join(popup_parts)
                self.view.show_popup(popup_text,
                                     sublime.HIDE_ON_MOUSE_MOVE_AWAY, point,
                                     600, 600, self.on_navigate, self.on_hide)