Skip to content

Commit 8400466

Browse files
committed
Remove error highlights when buffers are cleaned up
1 parent a1932b7 commit 8400466

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

autoload/ale/cleanup.vim

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ function! ale#cleanup#Buffer(buffer) abort
1313
" Clear delayed highlights for a buffer being removed.
1414
if g:ale_set_highlights
1515
call ale#highlight#UnqueueHighlights(a:buffer)
16+
call ale#highlight#RemoveHighlights([])
1617
endif
1718

1819
call remove(g:ale_buffer_info, a:buffer)

autoload/ale/highlight.vim

+13-6
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,25 @@ function! s:GetCurrentMatchIDs(loclist) abort
4646
return l:current_id_map
4747
endfunction
4848

49+
" Given a loclist for current items to highlight, remove all highlights
50+
" except these which have matching loclist item entries.
51+
function! ale#highlight#RemoveHighlights(loclist) abort
52+
let l:current_id_map = s:GetCurrentMatchIDs(a:loclist)
53+
54+
for l:match in s:GetALEMatches()
55+
if !has_key(l:current_id_map, l:match.id)
56+
call matchdelete(l:match.id)
57+
endif
58+
endfor
59+
endfunction
60+
4961
function! ale#highlight#UpdateHighlights() abort
5062
let l:buffer = bufnr('%')
5163
let l:has_new_items = has_key(s:buffer_highlights, l:buffer)
5264
let l:loclist = l:has_new_items ? remove(s:buffer_highlights, l:buffer) : []
53-
let l:current_id_map = s:GetCurrentMatchIDs(l:loclist)
5465

5566
if l:has_new_items || !g:ale_enabled
56-
for l:match in s:GetALEMatches()
57-
if !has_key(l:current_id_map, l:match.id)
58-
call matchdelete(l:match.id)
59-
endif
60-
endfor
67+
call ale#highlight#RemoveHighlights(l:loclist)
6168
endif
6269

6370
" Remove anything with a current match_id

test/test_highlight_placement.vader

+17
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,20 @@ Execute(Existing highlights should be kept):
7474
\ {'group': 'ALEWarning', 'id': 8, 'priority': 10, 'pos1': [4, 1, 1]},
7575
\ ],
7676
\ getmatches()
77+
78+
" This test is important for preventing ALE from showing highlights for
79+
" the wrong files.
80+
Execute(Highlights set by ALE should be removed when buffer cleanup is done):
81+
call ale#engine#InitBufferInfo(bufnr('%'))
82+
83+
call ale#highlight#SetHighlights(bufnr('%'), [
84+
\ {'bufnr': bufnr('%'), 'type': 'E', 'lnum': 3, 'col': 2},
85+
\])
86+
87+
AssertEqual
88+
\ [{'group': 'ALEError', 'id': 9, 'priority': 10, 'pos1': [3, 2, 1]}],
89+
\ getmatches()
90+
91+
call ale#cleanup#Buffer(bufnr('%'))
92+
93+
AssertEqual [], getmatches()

0 commit comments

Comments
 (0)