def on_navigate(self, url): if self.view.is_popup_visible(): self.view.hide_popup() if url[0:4] == 'http': webbrowser.open(url) elif url[0:8] == 'autofix:': rgn = symbols.Region.from_str(url[8:]) errs = parseoutput.errors_for_view(self.view) for err in errs: if err.correction is not None and err.correction.corrector.region == rgn: err.erase_from_view() parseoutput.ERRORS.remove(err) errs.remove(err) parseoutput.update_messages_in_view(self.view, errs) r = err.correction.corrector.to_region(self.view) sublime.set_timeout( lambda: self.view.run_command( 'sublime_haskell_replace_text', { 'text': err.correction.corrector.contents, 'begin': r.begin(), 'end': r.end() }), 0) return elif url[0:7] == "import:": self.view.run_command( 'sublime_haskell_insert_import_for_symbol', { 'filename': self.view.file_name(), 'decl': self.decl.name }) else: self.view.window().open_file( url, sublime.ENCODED_POSITION | sublime.TRANSIENT)
def on_navigate(self, url): if self.view.is_popup_visible(): self.view.hide_popup() if url[0:4] == 'http': webbrowser.open(url) elif url[0:8] == 'autofix:': rgn = symbols.Region.from_str(url[8:]) errs = parseoutput.errors_for_view(self.view) for err in errs: if err.correction is not None and err.correction.corrector.region == rgn: err.erase_from_view() parseoutput.ERRORS.remove(err) errs.remove(err) parseoutput.update_messages_in_view(self.view, errs) r = err.correction.corrector.to_region(self.view) sublime.set_timeout(lambda: self.view.run_command('sublime_haskell_replace_text', { 'text': err.correction.corrector.contents, 'begin': r.begin(), 'end': r.end() }), 0) return elif url[0:7] == "import:": self.view.run_command('sublime_haskell_insert_import_for_symbol', { 'filename': self.view.file_name(), 'decl': self.decl.name }) else: self.view.window().open_file(url, sublime.ENCODED_POSITION | sublime.TRANSIENT)
def on_hover(self, view, point, hover_zone): if not is_haskell_source(view): return self.view = view self.current_file_name = self.view.file_name() (line, column) = self.view.rowcol(point) self.decl = None self.typed_expr = None if hover_zone == sublime.HOVER_TEXT: qsymbol = 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 = head_of( hsdev.client.whois(self.whois_name, self.current_file_name)) if not self.decl: self.suggest_import = True self.decl = 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 = [ styles.gen_style(self.view.settings().get('color_scheme')) ] for err in errs: msg = 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)
def on_hover(self, view, point, hover_zone): if not is_haskell_source(view): return self.view = view self.current_file_name = self.view.file_name() (line, column) = self.view.rowcol(point) self.decl = None self.typed_expr = None if hover_zone == sublime.HOVER_TEXT: qsymbol = 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 = head_of(hsdev.client.whois(self.whois_name, self.current_file_name)) if not self.decl: self.suggest_import = True self.decl = 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 = [styles.gen_style(self.view.settings().get('color_scheme'))] for err in errs: msg = 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)