Skip to content

Commit 4d55a4a

Browse files
deathaxetomv564
authored andcommitted
Add separate gutter icons for errors/warnings/info
This commit provides the following changes: - Split phantom/regions creation into two separate functions. - Delete the phantomset from buffer, if no longer needed. - Create regions for errors/warnings/info with separate region names and scopes. - Use hard coded scope names and sync with recently modified diagnostics.sublime-syntax. - Disable phantoms by default, because some files really get unreadable due to too many of them. May have a look onto phantom styling later to beautify them a little bit? Note: I am not sure which legacy scoping is better sublimelinter or @rwols' solution, but we should decide for one to use everywhere.
1 parent 95cdbb9 commit 4d55a4a

File tree

3 files changed

+46
-37
lines changed

3 files changed

+46
-37
lines changed

LSP.sublime-settings

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,9 @@
4040
"show_status_messages": true,
4141
"show_view_status": true,
4242
"auto_show_diagnostics_panel": true,
43-
"show_diagnostics_phantoms": true,
43+
"show_diagnostics_phantoms": false,
4444
"show_diagnostics_in_view_status": true,
45-
"diagnostic_error_region_scope": "markup.error.lsp sublimelinter.mark.error",
4645
"log_debug": false,
4746
"log_server": true,
4847
"log_stderr": false
49-
5048
}

Syntaxes/Diagnostics.sublime-syntax

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ contexts:
4242

4343
expect-diag-type:
4444
# See: https://github.com/sublimehq/Packages/issues/1036
45-
# We use old markup scopes too so that old color schemes can catch up.
45+
# We use sublimelinter markup scopes too so that old color schemes can catch up.
4646
- include: pop-at-end
4747
- match: \berror\b
48-
scope: markup.error.lsp markup.deleted.lsp
48+
scope: markup.error.lsp sublimelinter.mark.error
4949
pop: true
5050
- match: \bwarning\b
51-
scope: markup.warning.lsp markup.heading.lsp
51+
scope: markup.warning.lsp sublimelinter.mark.warning
5252
pop: true
5353
- match: \binfo\b
54-
scope: markup.info.lsp markup.inserted.lsp
54+
scope: markup.info.lsp sublimelinter.gutter-mark
5555
pop: true
5656

5757
expect-linter-type:

main.py

+41-30
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
PLUGIN_NAME = 'LSP'
2525
SUBLIME_WORD_MASK = 515
26-
MARKUP_ERROR = 'markup.error.lsp sublimelinter.mark.error'
2726
show_status_messages = True
2827
show_view_status = True
2928
auto_show_diagnostics_panel = True
@@ -32,7 +31,6 @@
3231
log_debug = True
3332
log_server = True
3433
log_stderr = False
35-
diagnostic_error_region_scope = MARKUP_ERROR
3634

3735
configs = [] # type: List[ClientConfig]
3836

@@ -51,6 +49,13 @@ class DiagnosticSeverity(object):
5149
DiagnosticSeverity.Hint: "hint"
5250
}
5351

52+
diagnostic_severity_scopes = {
53+
DiagnosticSeverity.Error: 'markup.error.lsp sublimelinter.mark.error',
54+
DiagnosticSeverity.Warning: 'markup.warning.lsp sublimelinter.mark.warning',
55+
DiagnosticSeverity.Information: 'markup.info.lsp sublimelinter.gutter-mark',
56+
DiagnosticSeverity.Hint: 'markup.info.suggestion.lsp sublimelinter.gutter-mark'
57+
}
58+
5459

5560
class SymbolKind(object):
5661
File = 1
@@ -257,7 +262,6 @@ def update_settings(settings_obj: sublime.Settings):
257262
global auto_show_diagnostics_panel
258263
global show_diagnostics_phantoms
259264
global show_diagnostics_in_view_status
260-
global diagnostic_error_region_scope
261265
global log_debug
262266
global log_server
263267
global log_stderr
@@ -276,7 +280,6 @@ def update_settings(settings_obj: sublime.Settings):
276280
auto_show_diagnostics_panel = settings_obj.get("auto_show_diagnostics_panel", True)
277281
show_diagnostics_phantoms = settings_obj.get("show_diagnostics_phantoms", True)
278282
show_diagnostics_in_view_status = settings_obj.get("show_diagnostics_in_view_status", True)
279-
diagnostic_error_region_scope = settings_obj.get("diagnostic_error_region_scope", MARKUP_ERROR)
280283
log_debug = settings_obj.get("log_debug", False)
281284
log_server = settings_obj.get("log_server", True)
282285
log_stderr = settings_obj.get("log_stderr", False)
@@ -1149,37 +1152,45 @@ def update_file_diagnostics(window: sublime.Window, file_path: str, source: str,
11491152
phantom_sets_by_buffer = {} # type: Dict[int, sublime.PhantomSet]
11501153

11511154

1152-
def update_diagnostics_in_view(view: sublime.View, diagnostics: 'List[Diagnostic]'):
1155+
def update_diagnostics_phantoms(view: sublime.View, diagnostics: 'List[Diagnostic]'):
11531156
global phantom_sets_by_buffer
11541157

1155-
phantoms = [] # type: List[sublime.Phantom]
1156-
regions = [] # type: List[sublime.Region]
1158+
buffer_id = view.buffer_id()
1159+
if show_diagnostics_phantoms and not view.is_dirty():
1160+
phantoms = list(
1161+
create_phantom(view, diagnostic) for diagnostic in diagnostics)
1162+
else:
1163+
phantoms = None # type: ignore
1164+
if phantoms:
1165+
phantom_set = phantom_sets_by_buffer.get(buffer_id)
1166+
if not phantom_set:
1167+
phantom_set = sublime.PhantomSet(view, "lsp_diagnostics")
1168+
phantom_sets_by_buffer[buffer_id] = phantom_set
1169+
phantom_set.update(phantoms)
1170+
else:
1171+
phantom_sets_by_buffer.pop(buffer_id, None)
11571172

1158-
if view is not None:
1159-
if view.is_dirty() or not show_diagnostics_phantoms:
1160-
regions = list(
1161-
create_region(view, diagnostic) for diagnostic in diagnostics)
1162-
else:
1163-
phantoms = list(
1164-
create_phantom(view, diagnostic) for diagnostic in diagnostics)
11651173

1166-
# TODO: if phantoms are disabled, this logic can be skipped
1167-
buffer_id = view.buffer_id()
1168-
if buffer_id not in phantom_sets_by_buffer:
1169-
phantom_set = sublime.PhantomSet(view, "diagnostics")
1170-
phantom_sets_by_buffer[buffer_id] = phantom_set
1171-
else:
1172-
phantom_set = phantom_sets_by_buffer[buffer_id]
1174+
def update_diagnostics_regions(view: sublime.View, diagnostics: 'List[Diagnostic]', severity: int):
1175+
region_name = "lsp_" + format_severity(severity)
1176+
if show_diagnostics_phantoms and not view.is_dirty():
1177+
regions = None # type: ignore
1178+
else:
1179+
regions = list(create_region(view, diagnostic) for diagnostic in diagnostics
1180+
if diagnostic.severity == severity)
1181+
if regions:
1182+
scope_name = diagnostic_severity_scopes[severity]
1183+
view.add_regions(region_name, regions, scope_name, "dot",
1184+
sublime.DRAW_SQUIGGLY_UNDERLINE | UNDERLINE_FLAGS)
1185+
else:
1186+
view.erase_regions(region_name)
11731187

1174-
phantom_set.update(phantoms)
1175-
# TODO: split between warning and error
1176-
if (len(regions)) > 0:
1177-
# TODO: stop stealing SublimeLinter's coloring.
1178-
view.add_regions("lsp_errors", regions, diagnostic_error_region_scope,
1179-
"dot",
1180-
sublime.DRAW_SQUIGGLY_UNDERLINE | UNDERLINE_FLAGS)
1181-
else:
1182-
view.erase_regions("lsp_errors")
1188+
1189+
def update_diagnostics_in_view(view: sublime.View, diagnostics: 'List[Diagnostic]'):
1190+
if view and view.is_valid():
1191+
update_diagnostics_phantoms(view, diagnostics)
1192+
for severity in range(DiagnosticSeverity.Error, DiagnosticSeverity.Information):
1193+
update_diagnostics_regions(view, diagnostics, severity)
11831194

11841195

11851196
def remove_diagnostics(view: sublime.View):

0 commit comments

Comments
 (0)