Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions TypeScript.sublime-settings
Original file line number Diff line number Diff line change
Expand Up @@ -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": "",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means there's always a default, which means users haven't been seeing errors since we sent out the update last week.

"error_outlined": false,
"quick_info_popup_max_width": 1024
}
66 changes: 39 additions & 27 deletions typescript/commands/quick_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -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 '<br/>'.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")
Expand Down
7 changes: 6 additions & 1 deletion typescript/listeners/idle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+ is wrong, so this has never worked...

sublime.DRAW_SQUIGGLY_UNDERLINE)
Expand Down
2 changes: 1 addition & 1 deletion typescript/listeners/quick_info_tool_tip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)