@@ -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
112125endfunction
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
0 commit comments