23
23
24
24
PLUGIN_NAME = 'LSP'
25
25
SUBLIME_WORD_MASK = 515
26
- MARKUP_ERROR = 'markup.error.lsp sublimelinter.mark.error'
27
26
show_status_messages = True
28
27
show_view_status = True
29
28
auto_show_diagnostics_panel = True
32
31
log_debug = True
33
32
log_server = True
34
33
log_stderr = False
35
- diagnostic_error_region_scope = MARKUP_ERROR
36
34
37
35
configs = [] # type: List[ClientConfig]
38
36
@@ -51,6 +49,13 @@ class DiagnosticSeverity(object):
51
49
DiagnosticSeverity .Hint : "hint"
52
50
}
53
51
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
+
54
59
55
60
class SymbolKind (object ):
56
61
File = 1
@@ -257,7 +262,6 @@ def update_settings(settings_obj: sublime.Settings):
257
262
global auto_show_diagnostics_panel
258
263
global show_diagnostics_phantoms
259
264
global show_diagnostics_in_view_status
260
- global diagnostic_error_region_scope
261
265
global log_debug
262
266
global log_server
263
267
global log_stderr
@@ -276,7 +280,6 @@ def update_settings(settings_obj: sublime.Settings):
276
280
auto_show_diagnostics_panel = settings_obj .get ("auto_show_diagnostics_panel" , True )
277
281
show_diagnostics_phantoms = settings_obj .get ("show_diagnostics_phantoms" , True )
278
282
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 )
280
283
log_debug = settings_obj .get ("log_debug" , False )
281
284
log_server = settings_obj .get ("log_server" , True )
282
285
log_stderr = settings_obj .get ("log_stderr" , False )
@@ -1149,37 +1152,45 @@ def update_file_diagnostics(window: sublime.Window, file_path: str, source: str,
1149
1152
phantom_sets_by_buffer = {} # type: Dict[int, sublime.PhantomSet]
1150
1153
1151
1154
1152
- def update_diagnostics_in_view (view : sublime .View , diagnostics : 'List[Diagnostic]' ):
1155
+ def update_diagnostics_phantoms (view : sublime .View , diagnostics : 'List[Diagnostic]' ):
1153
1156
global phantom_sets_by_buffer
1154
1157
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 )
1157
1172
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 )
1165
1173
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 )
1173
1187
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 )
1183
1194
1184
1195
1185
1196
def remove_diagnostics (view : sublime .View ):
0 commit comments