@@ -337,10 +337,11 @@ function! s:ApplySemanticHighlights(bufnr, ns_id, clears, highlights) abort
337337endfunction
338338
339339" Batch version of nvim_buf_add_highlight
340- function ! s: AddHighlights (namespace_id , highlights) abort
340+ function ! s: AddHighlights (namespace , highlights) abort
341341 if has (' nvim' )
342+ let l: namespace_id = nvim_create_namespace (a: namespace )
342343 for hl in a: highlights
343- call nvim_buf_add_highlight (0 , a : namespace_id , hl .group, hl .line , hl .character_start, hl .character_end)
344+ call nvim_buf_add_highlight (0 , l : namespace_id , hl .group, hl .line , hl .character_start, hl .character_end)
344345 endfor
345346 else
346347 let match_ids = []
@@ -349,32 +350,27 @@ function! s:AddHighlights(namespace_id, highlights) abort
349350 let match_ids = add (match_ids, match_id)
350351 endfor
351352
352- call setbufvar (bufname (), ' document_highlight_match_ids ' , match_ids)
353+ call setbufvar (bufname (), a: namespace . ' _IDS ' , match_ids)
353354 endif
354355endfunction
355356
356- function ! s: SetHighlights (highlights) abort
357- call s: ClearHighlights ()
358- if has (' nvim' )
359- let s: namespace_id = nvim_create_namespace (' __LCN_DOCUMENT_HIGHLIGHTS__' )
360- call s: AddHighlights (s: namespace_id , a: highlights )
361- else
362- call s: AddHighlights (0 , a: highlights )
363- endif
357+ function ! s: SetHighlights (highlights, namespace) abort
358+ call s: ClearHighlights (a: namespace )
359+ call s: AddHighlights (a: namespace , a: highlights )
364360endfunction
365361
366- function ! s: ClearHighlights () abort
362+ function ! s: ClearHighlights (namespace ) abort
367363 if has (' nvim' )
368- let s : namespace_id = nvim_create_namespace (' __LCN_DOCUMENT_HIGHLIGHTS__ ' )
369- call nvim_buf_clear_namespace (0 , s : namespace_id , 0 , -1 )
364+ let l : namespace_id = nvim_create_namespace (a: namespace )
365+ call nvim_buf_clear_namespace (0 , l : namespace_id , 0 , -1 )
370366 else
371- let match_ids = get (b: , ' document_highlight_match_ids ' , [])
367+ let match_ids = get (b: , a: namespace . ' _IDS ' , [])
372368 for mid in match_ids
373369 " call inside a try/catch to avoid error for manually cleared matches
374370 try | call matchdelete (mid) | catch
375371 endtry
376372 endfor
377- call setbufvar (bufname (), ' document_highlight_match_ids ' , [])
373+ call setbufvar (bufname (), a: namespace . ' _IDS ' , [])
378374 endif
379375endfunction
380376
0 commit comments