@@ -27,7 +27,7 @@ function! lsp#internal#semantic#_enable() abort
27
27
\ lsp#callbag#fromEvent (l: events ),
28
28
\ lsp#callbag#filter ({_- >lsp#internal#semantic#is_enabled ()}),
29
29
\ lsp#callbag#debounceTime (g: lsp_semantic_delay ),
30
- \ lsp#callbag#filter ({_- >getbufvar (bufnr (' %' ), ' &buftype' ) !~# ' ^(help\|terminal\|prompt\|popup)$ ' }),
30
+ \ lsp#callbag#filter ({_- >index ([ ' help ' , ' terminal ' , ' prompt ' , ' popup ' ], getbufvar (bufnr (' %' ), ' &buftype' )) == # -1 }),
31
31
\ lsp#callbag#filter ({_- >! lsp#utils#is_large_window (win_getid ())}),
32
32
\ lsp#callbag#switchMap ({_- >
33
33
\ lsp#callbag#pipe (
@@ -212,8 +212,10 @@ endfunction
212
212
213
213
function ! s: handle_semantic_tokens_response (server, buf , result) abort
214
214
let l: highlights = {}
215
+ let l: legend = lsp#internal#semantic#get_legend (a: server )
215
216
for l: token in s: decode_tokens (a: result [' data' ])
216
- let l: highlights = s: add_highlight (l: highlights , a: server , a: buf , l: token )
217
+ let [l: key , l: value ] = s: add_highlight (a: server , l: legend , a: buf , l: token )
218
+ let l: highlights [l: key ] = get (l: highlights , l: key , []) + l: value
217
219
endfor
218
220
call s: apply_highlights (a: server , a: buf , l: highlights )
219
221
@@ -241,8 +243,10 @@ function! s:handle_semantic_tokens_delta_response(server, buf, result) abort
241
243
call setbufvar (a: buf , ' lsp_semantic_local_data' , l: localdata )
242
244
243
245
let l: highlights = {}
246
+ let l: legend = lsp#internal#semantic#get_legend (a: server )
244
247
for l: token in s: decode_tokens (l: localdata )
245
- let l: highlights = s: add_highlight (l: highlights , a: server , a: buf , l: token )
248
+ let [l: key , l: value ] = s: add_highlight (a: server , l: legend , a: buf , l: token )
249
+ let l: highlights [l: key ] = get (l: highlights , l: key , []) + l: value
246
250
endfor
247
251
call s: apply_highlights (a: server , a: buf , l: highlights )
248
252
endfunction
@@ -275,36 +279,32 @@ endfunction
275
279
276
280
function ! s: clear_highlights (server, buf ) abort
277
281
if s: use_vim_textprops
278
- let l: IsSemanticTextprop = {textprop - > textprop[' type' ] = ~ ' ^' . s: textprop_type_prefix . ' .*' }
279
- let l: textprop_types = prop_list (1 , {' bufnr' : a: buf , ' end_lnum' : -1 })
282
+ let l: BeginsWith = {str, prefix - > str[0 : len (prefix) - 1 ] == # prefix}
283
+ let l: IsSemanticTextprop = {_, textprop - > l: BeginsWith (textprop, s: textprop_type_prefix )}
284
+ let l: textprop_types = prop_type_list ()
280
285
call filter (l: textprop_types , l: IsSemanticTextprop )
281
286
for l: textprop_type in l: textprop_types
282
- silent ! call prop_remove ({' type' : l: textprop_type , ' bufnr' : a: buf , ' all' : v: true }, 1 , line ( ' $ ' ) )
287
+ silent ! call prop_remove ({' type' : l: textprop_type , ' bufnr' : a: buf , ' all' : v: true })
283
288
endfor
284
289
elseif s: use_nvim_highlight
285
290
call nvim_buf_clear_namespace (a: buf , s: namespace_id , 0 , line (' $' ))
286
291
endif
287
292
endfunction
288
293
289
- function ! s: add_highlight (highlights, server, buf , token) abort
290
- let l: legend = lsp#internal#semantic#get_legend (a: server )
294
+ function ! s: add_highlight (server, legend, buf , token) abort
291
295
let l: startpos = lsp#utils#position#lsp_to_vim (a: buf , a: token [' pos' ])
292
296
let l: endpos = a: token [' pos' ]
293
297
let l: endpos [' character' ] = l: endpos [' character' ] + a: token [' length' ]
294
298
let l: endpos = lsp#utils#position#lsp_to_vim (a: buf , l: endpos )
295
299
296
300
if s: use_vim_textprops
297
- let l: textprop_name = s: get_textprop_type (a: server , a: token [' token_idx' ], a: token [' token_modifiers' ])
298
- let a: highlights [l: textprop_name ] = get (a: highlights , l: textprop_name , [])
299
- \ + [[l: startpos [0 ], l: startpos [1 ], l: endpos [0 ], l: endpos [1 ]]]
301
+ let l: textprop_name = s: get_textprop_type (a: server , a: legend , a: token [' token_idx' ], a: token [' token_modifiers' ])
302
+ return [l: textprop_name , [[l: startpos [0 ], l: startpos [1 ], l: endpos [0 ], l: endpos [1 ]]]]
300
303
elseif s: use_nvim_highlight
301
304
let l: char = a: token [' pos' ][' character' ]
302
- let l: hl_name = s: get_hl_group (a: server , a: token [' token_idx' ], a: token [' token_modifiers' ])
303
- let a: highlights [l: hl_name ] = get (a: highlights , l: hl_name , [])
304
- \ + [[l: startpos [0 ] - 1 , l: startpos [1 ] - 1 , l: endpos [1 ] - 1 ]]
305
+ let l: hl_name = s: get_hl_group (a: server , a: legend , a: token [' token_idx' ], a: token [' token_modifiers' ])
306
+ return [l: hl_name , [[l: startpos [0 ] - 1 , l: startpos [1 ] - 1 , l: endpos [1 ] - 1 ]]]
305
307
endif
306
-
307
- return a: highlights
308
308
endfunction
309
309
310
310
function ! s: apply_highlights (server, buf , highlights) abort
@@ -342,28 +342,29 @@ let s:default_highlight_groups = {
342
342
\ s: hl_group_prefix . ' Variable' : ' Identifier' ,
343
343
\ s: hl_group_prefix . ' Property' : ' Identifier' ,
344
344
\ s: hl_group_prefix . ' EnumMember' : ' Constant' ,
345
- \ s: hl_group_prefix . ' Events ' : ' Identifier' ,
345
+ \ s: hl_group_prefix . ' Event ' : ' Identifier' ,
346
346
\ s: hl_group_prefix . ' Function' : ' Function' ,
347
347
\ s: hl_group_prefix . ' Method' : ' Function' ,
348
+ \ s: hl_group_prefix . ' Macro' : ' Macro' ,
348
349
\ s: hl_group_prefix . ' Keyword' : ' Keyword' ,
349
350
\ s: hl_group_prefix . ' Modifier' : ' Type' ,
350
351
\ s: hl_group_prefix . ' Comment' : ' Comment' ,
351
352
\ s: hl_group_prefix . ' String' : ' String' ,
352
353
\ s: hl_group_prefix . ' Number' : ' Number' ,
353
354
\ s: hl_group_prefix . ' Regexp' : ' String' ,
354
- \ s: hl_group_prefix . ' Operator' : ' Operator'
355
+ \ s: hl_group_prefix . ' Operator' : ' Operator' ,
356
+ \ s: hl_group_prefix . ' Decorator' : ' Macro'
355
357
\ }
356
358
357
- function ! s: get_hl_group (server, token_idx, token_modifiers) abort
359
+ function ! s: get_hl_group (server, legend, token_idx, token_modifiers) abort
358
360
" get highlight group name
359
- let l: legend = lsp#internal#semantic#get_legend (a: server )
360
361
let l: Capitalise = {str - > toupper (str[0 ]) . str[1 :]}
361
- let l: token_name = l: Capitalise (l : legend [' tokenTypes' ][a: token_idx ])
362
+ let l: token_name = l: Capitalise (a : legend [' tokenTypes' ][a: token_idx ])
362
363
let l: token_modifiers = []
363
- for l: modifier_idx in range (len (l : legend [' tokenModifiers' ]))
364
+ for l: modifier_idx in range (len (a : legend [' tokenModifiers' ]))
364
365
" float2nr(pow(2, a)) is 1 << a
365
366
if and (a: token_modifiers , float2nr (pow (2 , l: modifier_idx )))
366
- let l: modifier_name = l : legend [' tokenModifiers' ][l: modifier_idx ]
367
+ let l: modifier_name = a : legend [' tokenModifiers' ][l: modifier_idx ]
367
368
call add (l: token_modifiers , l: Capitalise (l: modifier_name ))
368
369
endif
369
370
endfor
@@ -378,7 +379,7 @@ function! s:get_hl_group(server, token_idx, token_modifiers) abort
378
379
exec ' highlight link' l: hl_group s: default_highlight_groups [l: hl_group ]
379
380
else
380
381
if a: token_modifiers != 0
381
- let l: base_hl_group = s: get_hl_group (a: server , a: token_idx , 0 )
382
+ let l: base_hl_group = s: get_hl_group (a: server , a: legend , a: token_idx , 0 )
382
383
exec ' highlight link' l: hl_group l: base_hl_group
383
384
else
384
385
exec ' highlight link' l: hl_group ' Normal'
@@ -391,13 +392,13 @@ endfunction
391
392
392
393
let s: textprop_type_prefix = ' vim-lsp-semantic-'
393
394
394
- function ! s: get_textprop_type (server, token_idx, token_modifiers) abort
395
+ function ! s: get_textprop_type (server, legend, token_idx, token_modifiers) abort
395
396
" get textprop type name
396
397
let l: textprop_type = s: textprop_type_prefix . a: server . ' -' . a: token_idx . ' -' . a: token_modifiers
397
398
398
399
" create the textprop type if it does not already exist
399
400
if prop_type_get (l: textprop_type ) == # {}
400
- let l: hl_group = s: get_hl_group (a: server , a: token_idx , a: token_modifiers )
401
+ let l: hl_group = s: get_hl_group (a: server , a: legend , a: token_idx , a: token_modifiers )
401
402
silent ! call prop_type_add (l: textprop_type , {
402
403
\ ' highlight' : l: hl_group ,
403
404
\ ' combine' : v: true ,
0 commit comments