Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support inline error tooltip at cursor position #546

Merged
merged 2 commits into from Oct 27, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions typescript/commands/error_info.py
Expand Up @@ -21,7 +21,10 @@ def run(self, text):
if region.contains(pt):
error_text = text
break

if len(error_text) > 0:
self.view.set_status("typescript_error", error_text)
else:
self.view.erase_status("typescript_error")
if PHANTOM_SUPPORT:
Copy link
Member

Choose a reason for hiding this comment

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

If show_errors_inline is set to false, do phantoms still appear? As this is an if/else, that would mean no error info. Is there a downside to always updating the status bar anyway?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, show_errors_inline only affects sublime's own error tips, it doesn't toggle all phantom tooltips. Though I agree we can always update the status bar anyway.

template = '<body><style>div.error {{ background-color: brown; padding: 5px; color: white }}</style><div class="error">{0}</div></body>'
display_text = template.format(error_text)
self.view.add_phantom("typescript_error", self.view.sel()[0], display_text, sublime.LAYOUT_BLOCK)
Copy link
Member

Choose a reason for hiding this comment

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

Interesting I don't see add_phantom on the view class in the docs (https://www.sublimetext.com/docs/3/api_reference.html#sublime.View). Maybe an oversight. They didn't make changes to this API after introducing it right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah it still exists in the latest version. I learnt it from the example at:
https://forum.sublimetext.com/t/dev-build-3118/21270

self.view.set_status("typescript_error", error_text)
2 changes: 2 additions & 0 deletions typescript/libs/global_vars.py
Expand Up @@ -42,6 +42,8 @@ def get_tsc_path():
# only Sublime Text 3 build after 3072 support tooltip
TOOLTIP_SUPPORT = int(sublime.version()) >= 3072

PHANTOM_SUPPORT = int(sublime.version()) >= 3118

# detect if quick info is available for symbol
SUBLIME_WORD_MASK = 515

Expand Down
6 changes: 4 additions & 2 deletions typescript/listeners/idle.py
Expand Up @@ -169,10 +169,12 @@ def show_errors(self, diagno_event_body, syntactic):
def update_status(self, view, info):
"""Update the status line with error info and quick info if no error info"""
# Error info
if PHANTOM_SUPPORT:
view.erase_phantoms("typescript_error")
view.erase_status("typescript_error")

if info.has_errors:
view.run_command('typescript_error_info')
else:
view.erase_status("typescript_error")

# Quick info
error_status = view.get_status('typescript_error')
Expand Down