def highlight_errors(self, errors): """ Highlights the relevant regions for each error in open views """ # We gather each error by the file view it should annotate # so we can add regions in bulk to each view. error_regions_by_view_id = {} warning_regions_by_view_id = {} for path, errors_by_path in groupby(errors, lambda error: error.span.filePath): view = self.find_view_for_path(path) for kind, errors_by_kind in groupby(errors_by_path, lambda error: error.kind): if kind == 'KindWarning': warning_regions_by_view_id[view.id()] = list(view_region_from_span(view, error.span) for error in errors_by_kind) else: error_regions_by_view_id[view.id()] = list(view_region_from_span(view, error.span) for error in errors_by_kind) # Add error/warning regions to their respective views for view in self.window.views(): view.add_regions("errors", error_regions_by_view_id.get(view.id(), []), "invalid", "dot", sublime.DRAW_OUTLINED) view.add_regions("warnings", warning_regions_by_view_id.get(view.id(), []), "comment", "dot", sublime.DRAW_OUTLINED)
def highlight_type(self, exp_types): """ ide-backend gives us a wealth of type info for the cursor. We only use the first, most specific one for now, but it gives us the types all the way out to the topmost expression. """ types = list(parse_exp_types(exp_types)) if types: # Display the first type in a region and in the status bar view = self.window.active_view() (type, span) = types[0] if span: if Win.show_popup: view.show_popup(type) view.set_status("type_at_cursor", type) view.add_regions("type_at_cursor", [view_region_from_span(view, span)], "storage.type", "", sublime.DRAW_OUTLINED) else: # Clear type-at-cursor display for view in self.window.views(): view.set_status("type_at_cursor", "") view.add_regions("type_at_cursor", [], "storage.type", "", sublime.DRAW_OUTLINED)
def highlight_type(self, exp_types): """ ide-backend gives us a wealth of type info for the cursor. We only use the first, most specific one for now, but it gives us the types all the way out to the topmost expression. """ type_spans = list(parse_exp_types(exp_types)) if type_spans: view = self.window.active_view() type_span = next(filter_enclosing(view, view.sel()[0], type_spans), None) if type_span is not None: (_type, span) = type_span view.set_status("type_at_cursor", _type) view.add_regions("type_at_cursor", [view_region_from_span(view, span)], "storage.type", "", sublime.DRAW_OUTLINED) if Win.show_popup: view.show_popup(format_type(_type), on_navigate= (lambda href: webbrowser.open(Win.hoogle_url + href))) return # Clear type-at-cursor display for view in self.window.views(): view.set_status("type_at_cursor", "") view.add_regions("type_at_cursor", [], "storage.type", "", sublime.DRAW_OUTLINED)