Skip to content

Commit

Permalink
Avoid repeatedly clearing and adding highlights
Browse files Browse the repository at this point in the history
Partially addresses natebosch#31

- Add a check comparing w:lsc_highlights_version and file against
  w:lsc_diagnotics_version and only recreate matches when there is a
  change.
- Change order of calls so that highlights are always updated after the
  diagnostics in the location list so that these variables are set and
  checked in the right order.
  • Loading branch information
natebosch committed Aug 19, 2017
1 parent 03eb193 commit a59c647
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Send file updates after re-reading already open file. Fixes some cases where
the server has a different idea of the file content than the editor.
- Avoid clearing and readding the same diagnostic matches each time diagnostics
change in some other file.

# 0.2.5

Expand Down
2 changes: 1 addition & 1 deletion autoload/lsc/diagnostics.vim
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ function! lsc#diagnostics#setForFile(file_path, diagnostics) abort
else
let s:diagnostic_versions[a:file_path] = 1
endif
call lsc#highlights#updateDisplayed()
call lsc#diagnostics#updateLocationList(a:file_path)
call lsc#highlights#updateDisplayed()
endfunction

" Updates location list for all windows showing [file_path].
Expand Down
15 changes: 15 additions & 0 deletions autoload/lsc/highlights.vim
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ endfunction

" Refresh highlight matches in the current window.
function! lsc#highlights#update() abort
if s:CurrentWindowIsFresh() | return | endif
call lsc#highlights#clear()
if !has_key(g:lsc_server_commands, &filetype) || &diff
return
Expand All @@ -16,6 +17,7 @@ function! lsc#highlights#update() abort
call add(w:lsc_diagnostic_matches, match)
endfor
endfor
call s:MarkCurrentWindowFresh()
endfunction!

" Remove all highlighted matches in the current window.
Expand All @@ -40,3 +42,16 @@ function! s:DeferForSelect() abort
endif
return v:false
endfunction

" Whether the diagnostic highlights for the current window are up to date.
function! s:CurrentWindowIsFresh() abort
if !exists('w:lsc_diagnostics_version') | return v:true | endif
if !exists('w:lsc_highlights_version') | return v:false | endif
return w:lsc_highlights_version == w:lsc_diagnostics_version &&
\ w:lsc_highlights_file == w:lsc_diagnostics_file
endfunction

function! s:MarkCurrentWindowFresh() abort
let w:lsc_highlights_version = w:lsc_diagnostics_version
let w:lsc_highlights_file = w:lsc_diagnostics_file
endfunction
2 changes: 1 addition & 1 deletion plugin/lsc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ function! LSCEnsureCurrentWindowState() abort
endif
return
endif
call lsc#highlights#update()
call lsc#diagnostics#updateLocationList(expand('%:p'))
call lsc#highlights#update()
endfunction

" Run `function` if LSC is enabled for the current filetype.
Expand Down

0 comments on commit a59c647

Please sign in to comment.