#333 Remember the IDs for highlights
This commit is contained in:
parent
382e569f66
commit
711ab99362
@ -22,12 +22,16 @@ function! ale#highlight#UnqueueHighlights(buffer) abort
|
|||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:RemoveOldHighlights() abort
|
function! s:GetALEMatches() abort
|
||||||
|
let l:list = []
|
||||||
|
|
||||||
for l:match in getmatches()
|
for l:match in getmatches()
|
||||||
if l:match['group'] ==# 'ALEError' || l:match['group'] ==# 'ALEWarning'
|
if l:match['group'] ==# 'ALEError' || l:match['group'] ==# 'ALEWarning'
|
||||||
call matchdelete(l:match['id'])
|
call add(l:list, l:match)
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
|
return l:list
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#highlight#UpdateHighlights() abort
|
function! ale#highlight#UpdateHighlights() abort
|
||||||
@ -36,7 +40,9 @@ function! ale#highlight#UpdateHighlights() abort
|
|||||||
let l:loclist = l:has_new_items ? remove(s:buffer_highlights, l:buffer) : []
|
let l:loclist = l:has_new_items ? remove(s:buffer_highlights, l:buffer) : []
|
||||||
|
|
||||||
if l:has_new_items || !g:ale_enabled
|
if l:has_new_items || !g:ale_enabled
|
||||||
call s:RemoveOldHighlights()
|
for l:match in s:GetALEMatches()
|
||||||
|
call matchdelete(l:match['id'])
|
||||||
|
endfor
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if l:has_new_items
|
if l:has_new_items
|
||||||
@ -46,7 +52,10 @@ function! ale#highlight#UpdateHighlights() abort
|
|||||||
let l:line = l:item.lnum
|
let l:line = l:item.lnum
|
||||||
let l:size = 1
|
let l:size = 1
|
||||||
|
|
||||||
call matchaddpos(l:group, [[l:line, l:col, l:size]])
|
" Rememeber the match ID for the item.
|
||||||
|
" This ID will be used to preserve loclist items which are set
|
||||||
|
" many times.
|
||||||
|
let l:item.match_id = matchaddpos(l:group, [[l:line, l:col, l:size]])
|
||||||
endfor
|
endfor
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
@ -64,7 +73,7 @@ function! ale#highlight#SetHighlights(buffer, loclist) abort
|
|||||||
"
|
"
|
||||||
" We'll filter the loclist down to items we can set now.
|
" We'll filter the loclist down to items we can set now.
|
||||||
let s:buffer_highlights[a:buffer] = filter(
|
let s:buffer_highlights[a:buffer] = filter(
|
||||||
\ deepcopy(a:loclist),
|
\ copy(a:loclist),
|
||||||
\ 'v:val.bufnr == a:buffer && v:val.col > 0'
|
\ 'v:val.bufnr == a:buffer && v:val.col > 0'
|
||||||
\)
|
\)
|
||||||
|
|
||||||
|
@ -125,8 +125,7 @@ function! ale#sign#SetSigns(buffer, loclist) abort
|
|||||||
\ : 'ALEWarningSign'
|
\ : 'ALEWarningSign'
|
||||||
|
|
||||||
" Save the sign IDs we are setting back on our loclist objects.
|
" Save the sign IDs we are setting back on our loclist objects.
|
||||||
" These IDs can be used later for changing line numbers of items
|
" These IDs will be used to preserve items which are set many times.
|
||||||
" we keep, based on what Vim adjusts automatically.
|
|
||||||
for l:obj in l:sublist
|
for l:obj in l:sublist
|
||||||
let l:obj.sign_id = l:sign_id
|
let l:obj.sign_id = l:sign_id
|
||||||
endfor
|
endfor
|
||||||
|
@ -4,27 +4,18 @@ Before:
|
|||||||
\ {
|
\ {
|
||||||
\ 'lnum': 1,
|
\ 'lnum': 1,
|
||||||
\ 'col': 1,
|
\ 'col': 1,
|
||||||
\ 'bufnr': bufnr('%'),
|
|
||||||
\ 'vcol': 0,
|
|
||||||
\ 'nr': -1,
|
|
||||||
\ 'type': 'E',
|
\ 'type': 'E',
|
||||||
\ 'text': 'foo',
|
\ 'text': 'foo',
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
\ 'lnum': 2,
|
\ 'lnum': 2,
|
||||||
\ 'col': 1,
|
\ 'col': 1,
|
||||||
\ 'bufnr': bufnr('%'),
|
|
||||||
\ 'vcol': 0,
|
|
||||||
\ 'nr': -1,
|
|
||||||
\ 'type': 'W',
|
\ 'type': 'W',
|
||||||
\ 'text': 'bar',
|
\ 'text': 'bar',
|
||||||
\ },
|
\ },
|
||||||
\ {
|
\ {
|
||||||
\ 'lnum': 3,
|
\ 'lnum': 3,
|
||||||
\ 'col': 5,
|
\ 'col': 5,
|
||||||
\ 'bufnr': bufnr('%'),
|
|
||||||
\ 'vcol': 0,
|
|
||||||
\ 'nr': -1,
|
|
||||||
\ 'type': 'E',
|
\ 'type': 'E',
|
||||||
\ 'text': 'wat',
|
\ 'text': 'wat',
|
||||||
\ },
|
\ },
|
||||||
@ -59,3 +50,5 @@ Execute(Highlights should be set when a linter runs):
|
|||||||
\ {'group': 'ALEError', 'id': 6, 'priority': 10, 'pos1': [3, 5, 1]}
|
\ {'group': 'ALEError', 'id': 6, 'priority': 10, 'pos1': [3, 5, 1]}
|
||||||
\ ],
|
\ ],
|
||||||
\ getmatches()
|
\ getmatches()
|
||||||
|
|
||||||
|
AssertEqual [4, 5, 6], map(copy(g:ale_buffer_info[bufnr('')].loclist), 'v:val.match_id')
|
||||||
|
@ -36,4 +36,8 @@ Execute(The loclist should be updated after linting is done):
|
|||||||
call ale#engine#WaitForJobs(2000)
|
call ale#engine#WaitForJobs(2000)
|
||||||
|
|
||||||
AssertEqual ['' . bufnr('%')], keys(g:ale_buffer_info)
|
AssertEqual ['' . bufnr('%')], keys(g:ale_buffer_info)
|
||||||
|
|
||||||
|
let g:expected_data[0].match_id = getmatches()[0].id
|
||||||
|
let g:expected_data[1].match_id = getmatches()[1].id
|
||||||
|
|
||||||
AssertEqual g:expected_data, g:ale_buffer_info[bufnr('%')].loclist
|
AssertEqual g:expected_data, g:ale_buffer_info[bufnr('%')].loclist
|
||||||
|
Loading…
Reference in New Issue
Block a user