Skip to content
This repository was archived by the owner on Sep 24, 2024. It is now read-only.

Commit 031d222

Browse files
committed
Fix final skipped region not clearing (fixes #61)
* workaround empty notifications being sent via timer
1 parent a4ff9d3 commit 031d222

File tree

3 files changed

+73
-2
lines changed

3 files changed

+73
-2
lines changed

autoload/lsp_cxx_hl/hl.vim

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,26 @@ function! lsp_cxx_hl#hl#notify_skipped(bufnr, skipped) abort
9292
if get(b:, 'lsp_cxx_hl_disabled', 0)
9393
call lsp_cxx_hl#hl#clear()
9494
else
95-
call lsp_cxx_hl#textprop_nvim#skipped#notify(a:bufnr, a:skipped)
95+
if !empty(a:skipped)
96+
call lsp_cxx_hl#textprop_nvim#skipped#notify(a:bufnr, a:skipped)
97+
call s:stop_clear(a:bufnr, 'skipped_clear_timer')
98+
else
99+
call s:start_clear(a:bufnr, 'skipped_clear_timer',
100+
\ function('lsp_cxx_hl#textprop_nvim#skipped#clear'
101+
\ ))
102+
endif
96103
endif
97104
elseif g:lsp_cxx_hl_use_text_props
98105
if get(b:, 'lsp_cxx_hl_disabled', 0)
99106
call lsp_cxx_hl#hl#clear()
100107
else
101-
call lsp_cxx_hl#textprop#skipped#notify(a:bufnr, a:skipped)
108+
if !empty(a:skipped)
109+
call lsp_cxx_hl#textprop#skipped#notify(a:bufnr, a:skipped)
110+
call s:stop_clear(a:bufnr, 'skipped_clear_timer')
111+
else
112+
call s:start_clear(a:bufnr, 'skipped_clear_timer',
113+
\ function('lsp_cxx_hl#textprop#skipped#clear'))
114+
endif
102115
endif
103116
else
104117
call lsp_cxx_hl#match#skipped#notify(a:bufnr, a:skipped)
@@ -110,3 +123,44 @@ function! lsp_cxx_hl#hl#notify_skipped(bufnr, skipped) abort
110123
endif
111124
endif
112125
endfunction
126+
127+
" Helper for running clear after some time has passed this clears the last
128+
" symbol or skipped region leftover after a
129+
" user deletes it
130+
let s:has_timers = has('timers')
131+
function! s:start_clear(bufnr, timer_var, ClearFn) abort
132+
if !s:has_timers
133+
call lsp_cxx_hl#log('WARNING: timers not available, '
134+
\ 'delay cannot be done!')
135+
call a:ClearFn()
136+
return
137+
endif
138+
139+
let l:timer = getbufvar(a:bufnr, a:timer_var, -1)
140+
if l:timer != -1
141+
call timer_stop(l:timer)
142+
endif
143+
144+
let l:timer = timer_start(g:lsp_cxx_hl_clear_delay_ms,
145+
\ function('s:clear_timer_fn',
146+
\ [a:bufnr, a:timer_var, a:ClearFn]))
147+
call setbufvar(a:bufnr, a:timer_var, l:timer)
148+
endfunction
149+
150+
function! s:stop_clear(bufnr, timer_var) abort
151+
if !s:has_timers
152+
return
153+
endif
154+
155+
let l:timer = getbufvar(a:bufnr, a:timer_var, -1)
156+
if l:timer != -1
157+
call timer_stop(l:timer)
158+
endif
159+
call setbufvar(a:bufnr, a:timer_var, -1)
160+
endfunction
161+
162+
function! s:clear_timer_fn(bufnr, timer_var, ClearFn, timer) abort
163+
call lsp_cxx_hl#verbose_log(a:timer_var, ' clear_timer_fn ', l:timer)
164+
call a:ClearFn(a:bufnr)
165+
call setbufvar(a:bufnr, a:timer_var, -1)
166+
endfunction

doc/vim-lsp-cxx-highlight.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,22 @@ Default = 0.
210210
let g:lsp_cxx_hl_light_bg = 1
211211
<
212212

213+
-------------------------------------------------------------------------------
214+
215+
*lsp_cxx_hl_clear_delay_ms* *g:lsp_cxx_hl_clear_delay_ms*
216+
g:lsp_cxx_hl_clear_delay_ms
217+
218+
Clear delay for the last remaining skipped region. This is a workaround for
219+
debouncing erratic empty ccls notifications that appear upon saving.
220+
221+
Generally should be set to longer than it takes to compile the file or else
222+
highlighting will flash when saving.
223+
224+
Default = 30000.
225+
>
226+
let g:lsp_cxx_hl_clear_delay_ms = 10000
227+
<
228+
213229
===============================================================================
214230

215231
*vim-lsp-cxx-highlight-highlight-groups*

plugin/vim-lsp-cxx-highlight.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ let g:lsp_cxx_hl_use_nvim_text_props = get(g:,
2323
let g:lsp_cxx_hl_text_prop_refresh_count = get(g:,
2424
\ 'lsp_cxx_hl_text_prop_refresh_count', 10)
2525
let g:lsp_cxx_hl_light_bg = get(g:, 'lsp_cxx_hl_light_bg', 0)
26+
let g:lsp_cxx_hl_clear_delay_ms = get(g:, 'lsp_cxx_hl_clear_delay_ms', 30000)
2627

2728
function s:initialize() abort
2829
let l:ok = 0

0 commit comments

Comments
 (0)