Skip to content

Commit

Permalink
Suppress diagnostics on the current line
Browse files Browse the repository at this point in the history
See #169

When typing it is common for there to be diagnostics while the code is
in an incomplete state. Suppress these diagnostics until after leaving
insert mode.

This has the unfortunate side effect of also removing existing
diagnostics from the current line even if they weren't impacted by the
changed text.
  • Loading branch information
natebosch committed Apr 2, 2019
1 parent b02690e commit 237c560
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions autoload/lsc/highlights.vim
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,34 @@ function! lsc#highlights#update() abort
if s:CurrentWindowIsFresh() | return | endif
call lsc#highlights#clear()
if &diff | return | endif
for line in values(lsc#diagnostics#forFile(lsc#file#fullPath()))
for diagnostic in line
let match = matchaddpos(diagnostic.group, diagnostic.ranges, -1)
call add(w:lsc_diagnostic_matches, match)
endfor
let l:is_insert = mode() == 'i'
if exists('w:lsc_diagnostic_deferred')
unlet w:lsc_diagnostic_deferred
endif
for [line, diagnostics] in items(lsc#diagnostics#forFile(lsc#file#fullPath()))
if l:is_insert && l:line == line('.')
let w:lsc_diagnostic_deferred = l:diagnostics
call lsc#util#once('CursorHold,CursorMoved',
\ function('<SID>UpdateDeferred'))
else
for diagnostic in l:diagnostics
let match = matchaddpos(diagnostic.group, diagnostic.ranges, -1)
call add(w:lsc_diagnostic_matches, match)
endfor
endif
endfor
call s:MarkCurrentWindowFresh()
endfunction

function! s:UpdateDeferred() abort
if !exists('w:lsc_diagnostic_deferred') | return | endif
for l:diagnostic in w:lsc_diagnostic_deferred
let match = matchaddpos(diagnostic.group, diagnostic.ranges, -1)
call add(w:lsc_diagnostic_matches, match)
endfor
unlet w:lsc_diagnostic_deferred
endfunction

" Remove all highlighted matches in the current window.
function! lsc#highlights#clear() abort
if exists('w:lsc_diagnostic_matches')
Expand Down

0 comments on commit 237c560

Please sign in to comment.