microsoft / TypeScript-Sublime-Plugin

IO wrapper around TypeScript language services, allowing for easy consumption by editor plugins
Apache License 2.0
1.72k stars 235 forks source link

Diagnostics for an empty region does not show up #637

Open univerio opened 6 years ago

univerio commented 6 years ago

I'm using tslint-language-service, and it works fine except for rules like semicolon or trailing-comma. The diagnostics produced by these rules correctly end up in Sublime, but they don't get rendered because they appear inside an empty region at the end of the line and Sublime refuses to render them:

image

I've added a quick workaround, like this:

diff --git typescript/listeners/idle.py typescript/listeners/idle.py
index f48df56..30e6a8f 100644
--- typescript/listeners/idle.py
+++ typescript/listeners/idle.py
@@ -146,6 +146,9 @@ class IdleListener:
                     # character instead so user can still see the highlight.
                     if start == view.size() and start == end:
                         region = last_visible_character_region(view)
+                    elif start == view.line(start).end() and start == end:
+                        end = view.text_point(start_line + 1, 0)
+                        region = sublime.Region(start, end)
                     else:
                         region = sublime.Region(start, end)

which seems to at least put a small red squiggle at the end of the line:

image

but hovering over it to get the message doesn't work. It also seems that the issue is more general, in that any region that only contains whitespace does not show up, e.g. when I add some trailing spaces:

image

so while this is a conservative change that solves this specific issue with semicolon and trailing-comma, I'm not sure this is the right solution in the general case. SublimeLinter adds a gutter mark for empty regions, so maybe that's a viable solution?

For reference, this behaves properly in VSCode:

image image