diff --git a/README.md b/README.md index 6f172ebd..06e695cb 100644 --- a/README.md +++ b/README.md @@ -98,7 +98,9 @@ for OS-specific shortcuts. These settings can be overridden in `Packages/User/TypeScript.sublime-settings`, which you can open by going to `Preferences` -> `Package Settings` -> `TypeScript` -> `TypeScript Settings - User`. -- `error_color`: the color of the squiggly lines drawn underneath type errors; either an empty string for the default color, or one of `"region.redish"`, `"region.orangish"`, `"region.yellowish"`, `"region.greenish"`, `"region.bluish"`, `"region.purplish"`, `"region.pinkish"` +- `error_color`: the color of the lines drawn underneath/around type errors; either an empty string for the default color, or one of `"region.redish"`, `"region.orangish"`, `"region.yellowish"`, `"region.greenish"`, `"region.bluish"`, `"region.purplish"`, `"region.pinkish"` +- `error_icon`: specifies a gutter icon, defaults to nothing can be set to `"dot"`, `"circle"`, `"bookmark"` or any other value accepted by Sublime Text +- `error_outlined`: will draw type errors with a solid outline instead of the default which is a squiggly line underneath - `quick_info_popup_max_width`: the max width of the quick info popup, default 1024 Project System diff --git a/TypeScript.sublime-settings b/TypeScript.sublime-settings index 7666555c..2c113dc3 100644 --- a/TypeScript.sublime-settings +++ b/TypeScript.sublime-settings @@ -5,5 +5,7 @@ // empty string, or one of "region.redish", "region.orangish", "region.yellowish", "region.greenish", "region.bluish", "region.purplish", "region.pinkish" "error_color": "", + "error_icon": "", + "error_outlined": false, "quick_info_popup_max_width": 1024 } diff --git a/typescript/commands/quick_info.py b/typescript/commands/quick_info.py index 3c999559..a44631a6 100644 --- a/typescript/commands/quick_info.py +++ b/typescript/commands/quick_info.py @@ -64,23 +64,21 @@ def handle_quick_info(self, quick_info_resp_dict, display_point): else: self.view.erase_status("typescript_info") - # process tooltips - error_html = self.get_error_text_html(display_point) - if TOOLTIP_SUPPORT and (info_str != "" or doc_str != "" or error_html != ""): - if self.template is None: - self.template = Template(load_quickinfo_and_error_popup_template()) - html = self.get_popup_html(error_html, info_str, doc_str) + # Fetch any errors and show tooltips if available + error_html = self.get_error_text_html(sublime.Region(display_point, display_point)) + if info_str != "" or doc_str != "" or error_html != "": + self.show_tooltip_popup(display_point, error_html, info_str, doc_str) - settings = sublime.load_settings("TypeScript.sublime-settings") - self.view.show_popup(html, flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, location=display_point, max_height=300, max_width=settings.get("quick_info_popup_max_width") or self.view.viewport_extent()[0]) + def show_tooltip_popup(self, display_point, error, info, doc): + if not TOOLTIP_SUPPORT: + return - def get_popup_html(self, error, info, doc): theme_styles = get_theme_styles(self.view) parameters = { - "error": error, - "info_str": info, - "doc_str": doc, + "error": error or '', + "info_str": info or '', + "doc_str": doc or '', "typeStyles": theme_styles["type"], "keywordStyles": theme_styles["keyword"], "nameStyles": theme_styles["name"], @@ -95,26 +93,40 @@ def get_popup_html(self, error, info, doc): "textStyles": theme_styles["text"] } - return self.template.substitute(parameters) + if self.template is None: + self.template = Template(load_quickinfo_and_error_popup_template()) + html = self.template.substitute(parameters) - def get_error_text_html(self, pt): + settings = sublime.load_settings("TypeScript.sublime-settings") + self.view.show_popup( + html, + flags=sublime.HIDE_ON_MOUSE_MOVE_AWAY, + location=display_point, + max_height=300, + max_width=settings.get("quick_info_popup_max_width") or self.view.viewport_extent()[0] + ) + + def get_error_text_html(self, span): client_info = cli.get_or_add_file(self.view.file_name()) - error_text = "" - for (region, text) in client_info.errors['syntacticDiag']: - if region.contains(pt): - error_text = text - break - for (region, text) in client_info.errors['semanticDiag']: - if region.contains(pt): - error_text = text - break - return escape_html(error_text) - - def run(self, text, hover_point=None): + all_errors = client_info.errors['syntacticDiag'] + client_info.errors['semanticDiag'] + + errors = [] + for (region, text) in all_errors: + if region.intersects(span): + errors.append(escape_html(text)) + + return '
'.join(errors) + + def run(self, text, hover_point=None, hover_zone=None): check_update_view(self.view) display_point = self.view.sel()[0].begin() if hover_point is None else hover_point word_at_sel = self.view.classify(display_point) - if word_at_sel & SUBLIME_WORD_MASK: + if hover_zone == sublime.HOVER_GUTTER: + line_span = self.view.full_line(display_point) + error_html = self.get_error_text_html(line_span) + if error_html: + self.show_tooltip_popup(display_point, error_html, None, None) + elif word_at_sel & SUBLIME_WORD_MASK: cli.service.quick_info_full(self.view.file_name(), get_location_from_position(self.view, display_point), lambda response: self.handle_quick_info(response, display_point)) else: self.view.erase_status("typescript_info") diff --git a/typescript/listeners/idle.py b/typescript/listeners/idle.py index 5903dc76..c3a66912 100644 --- a/typescript/listeners/idle.py +++ b/typescript/listeners/idle.py @@ -162,7 +162,12 @@ def show_errors(self, diagno_event_body, syntactic): sublime.DRAW_OUTLINED) else: settings = sublime.load_settings("TypeScript.sublime-settings") - view.add_regions(region_key, error_regions, settings.get("error_color") or "invalid.illegal", "", + view.add_regions(region_key, + error_regions, + settings.get("error_color", "invalid.illegal"), + settings.get("error_icon", ""), + sublime.DRAW_OUTLINED + if settings.get("error_outlined") else sublime.DRAW_NO_FILL + sublime.DRAW_NO_OUTLINE + sublime.DRAW_SQUIGGLY_UNDERLINE) diff --git a/typescript/listeners/quick_info_tool_tip.py b/typescript/listeners/quick_info_tool_tip.py index 45d79780..696f2262 100644 --- a/typescript/listeners/quick_info_tool_tip.py +++ b/typescript/listeners/quick_info_tool_tip.py @@ -5,7 +5,7 @@ class QuickInfoToolTipEventListener: def on_hover(self, view, point, hover_zone): - view.run_command('typescript_quick_info_doc', {"hover_point": point}) + view.run_command('typescript_quick_info_doc', {"hover_point": point, "hover_zone": hover_zone}) listen = QuickInfoToolTipEventListener() EventHub.subscribe("on_hover", listen.on_hover)