Skip to content

Commit

Permalink
Remove error highlights when buffers are cleaned up
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rp committed Apr 19, 2017
1 parent a1932b7 commit 8400466
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
1 change: 1 addition & 0 deletions autoload/ale/cleanup.vim
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function! ale#cleanup#Buffer(buffer) abort
" Clear delayed highlights for a buffer being removed.
if g:ale_set_highlights
call ale#highlight#UnqueueHighlights(a:buffer)
call ale#highlight#RemoveHighlights([])
endif

call remove(g:ale_buffer_info, a:buffer)
Expand Down
19 changes: 13 additions & 6 deletions autoload/ale/highlight.vim
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,25 @@ function! s:GetCurrentMatchIDs(loclist) abort
return l:current_id_map
endfunction

" Given a loclist for current items to highlight, remove all highlights
" except these which have matching loclist item entries.
function! ale#highlight#RemoveHighlights(loclist) abort
let l:current_id_map = s:GetCurrentMatchIDs(a:loclist)

for l:match in s:GetALEMatches()
if !has_key(l:current_id_map, l:match.id)
call matchdelete(l:match.id)
endif
endfor
endfunction

function! ale#highlight#UpdateHighlights() abort
let l:buffer = bufnr('%')
let l:has_new_items = has_key(s:buffer_highlights, l:buffer)
let l:loclist = l:has_new_items ? remove(s:buffer_highlights, l:buffer) : []
let l:current_id_map = s:GetCurrentMatchIDs(l:loclist)

if l:has_new_items || !g:ale_enabled
for l:match in s:GetALEMatches()
if !has_key(l:current_id_map, l:match.id)
call matchdelete(l:match.id)
endif
endfor
call ale#highlight#RemoveHighlights(l:loclist)
endif

" Remove anything with a current match_id
Expand Down
17 changes: 17 additions & 0 deletions test/test_highlight_placement.vader
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,20 @@ Execute(Existing highlights should be kept):
\ {'group': 'ALEWarning', 'id': 8, 'priority': 10, 'pos1': [4, 1, 1]},
\ ],
\ getmatches()

" This test is important for preventing ALE from showing highlights for
" the wrong files.
Execute(Highlights set by ALE should be removed when buffer cleanup is done):
call ale#engine#InitBufferInfo(bufnr('%'))

call ale#highlight#SetHighlights(bufnr('%'), [
\ {'bufnr': bufnr('%'), 'type': 'E', 'lnum': 3, 'col': 2},
\])

AssertEqual
\ [{'group': 'ALEError', 'id': 9, 'priority': 10, 'pos1': [3, 2, 1]}],
\ getmatches()

call ale#cleanup#Buffer(bufnr('%'))

AssertEqual [], getmatches()

0 comments on commit 8400466

Please sign in to comment.