예제 #1
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)
예제 #2
0
 def __init__(self):
     super().__init__()
     self.autocompleter = Autocomplete.AutoCompleter()
     self.backend_mgr = BackendManager.BackendManager()
     self.type_cache = Types.SourceHaskellTypeCache()
     # I get two calls of `on_post_save` after saving file
     # To prevent extra calls to check/infer etc., we store here last updated time
     # view => (view.update_count(), time.clock())
     self.update_cache = {}
예제 #3
0
 def __init__(self):
     super().__init__()
     self.backend_mgr = BackendManager.BackendManager()
     self.type_cache = Types.SourceHaskellTypeCache()
     self.autocompleter = Autocomplete.AutoCompleter()
     # Fly mode state:
     self.fly_view = LockedObject.LockedObject({'view': None, 'mtime': None})
     self.fly_event = threading.Event()
     self.fly_agent = threading.Thread(target='fly_check')
예제 #4
0
 def __init__(self, view):
     super().__init__(view)
     self.autocompleter = Autocomplete.AutoCompleter()
     self.backend_mgr = BackendManager.BackendManager()
     self.type_cache = Types.SourceHaskellTypeCache()