#653 - Filter items based on the buffer number for signs
This commit is contained in:
parent
ea124c49d0
commit
2d02de33d4
@ -104,11 +104,15 @@ function! ale#sign#FindCurrentSigns(buffer) abort
|
||||
endfunction
|
||||
|
||||
" Given a loclist, group the List into with one List per line.
|
||||
function! s:GroupLoclistItems(loclist) abort
|
||||
function! s:GroupLoclistItems(buffer, loclist) abort
|
||||
let l:grouped_items = []
|
||||
let l:last_lnum = -1
|
||||
|
||||
for l:obj in a:loclist
|
||||
if l:obj.bufnr != a:buffer
|
||||
continue
|
||||
endif
|
||||
|
||||
" Create a new sub-List when we hit a new line.
|
||||
if l:obj.lnum != l:last_lnum
|
||||
call add(l:grouped_items, [])
|
||||
@ -231,11 +235,11 @@ function! s:PlaceNewSigns(buffer, grouped_items, current_sign_offset) abort
|
||||
endfunction
|
||||
|
||||
" Get items grouped by any current sign IDs they might have.
|
||||
function! s:GetItemsWithSignIDs(loclist) abort
|
||||
function! s:GetItemsWithSignIDs(buffer, loclist) abort
|
||||
let l:items_by_sign_id = {}
|
||||
|
||||
for l:item in a:loclist
|
||||
if has_key(l:item, 'sign_id')
|
||||
if l:item.bufnr == a:buffer && has_key(l:item, 'sign_id')
|
||||
if !has_key(l:items_by_sign_id, l:item.sign_id)
|
||||
let l:items_by_sign_id[l:item.sign_id] = []
|
||||
endif
|
||||
@ -273,14 +277,14 @@ function! ale#sign#SetSigns(buffer, loclist) abort
|
||||
" Find the current markers
|
||||
let l:current_sign_list = ale#sign#FindCurrentSigns(a:buffer)
|
||||
" Get a mapping from sign IDs to current loclist items which have them.
|
||||
let l:items_by_sign_id = s:GetItemsWithSignIDs(a:loclist)
|
||||
let l:items_by_sign_id = s:GetItemsWithSignIDs(a:buffer, a:loclist)
|
||||
|
||||
" Use sign information to update the line numbers for the loclist items.
|
||||
call s:UpdateLineNumbers(l:current_sign_list, l:items_by_sign_id)
|
||||
" Sort items again, as the line numbers could have changed.
|
||||
call sort(a:loclist, 'ale#util#LocItemCompare')
|
||||
|
||||
let l:grouped_items = s:GroupLoclistItems(a:loclist)
|
||||
let l:grouped_items = s:GroupLoclistItems(a:buffer, a:loclist)
|
||||
|
||||
" Set the dummy sign if we need to.
|
||||
" This keeps the sign gutter open while we remove things, etc.
|
||||
|
@ -124,7 +124,6 @@ Execute(The current signs should be set for running a job):
|
||||
\ ],
|
||||
\ ParseSigns()
|
||||
|
||||
|
||||
Execute(Loclist items with sign_id values should be kept):
|
||||
exec 'sign place 1000347 line=3 name=ALEErrorSign buffer=' . bufnr('%')
|
||||
exec 'sign place 1000348 line=15 name=ALEErrorSign buffer=' . bufnr('%')
|
||||
@ -169,5 +168,32 @@ Execute(Loclist items with sign_id values should be kept):
|
||||
\ ],
|
||||
\ sort(ParseSigns())
|
||||
|
||||
Execute(Items for other buffers should be ignored):
|
||||
let g:loclist = [
|
||||
\ {'bufnr': bufnr('') - 1, 'lnum': 1, 'col': 1, 'type': 'E', 'text': 'a'},
|
||||
\ {'bufnr': bufnr('') - 1, 'lnum': 2, 'col': 1, 'type': 'E', 'text': 'a', 'sign_id': 1000347},
|
||||
\ {'bufnr': bufnr(''), 'lnum': 1, 'col': 1, 'type': 'E', 'text': 'a'},
|
||||
\ {'bufnr': bufnr(''), 'lnum': 2, 'col': 1, 'type': 'W', 'text': 'b'},
|
||||
\ {'bufnr': bufnr(''), 'lnum': 3, 'col': 1, 'type': 'E', 'text': 'c'},
|
||||
\ {'bufnr': bufnr(''), 'lnum': 4, 'col': 1, 'type': 'W', 'text': 'd'},
|
||||
\ {'bufnr': bufnr(''), 'lnum': 15, 'col': 2, 'type': 'W', 'text': 'e'},
|
||||
\ {'bufnr': bufnr(''), 'lnum': 16, 'col': 2, 'type': 'E', 'text': 'f'},
|
||||
\ {'bufnr': bufnr('') + 1, 'lnum': 1, 'col': 1, 'type': 'E', 'text': 'a'},
|
||||
\]
|
||||
|
||||
call ale#sign#SetSigns(bufnr(''), g:loclist)
|
||||
call ale#sign#RemoveDummySignIfNeeded(bufnr(''))
|
||||
|
||||
AssertEqual
|
||||
\ [
|
||||
\ ['1', '1000001', 'ALEErrorSign'],
|
||||
\ ['15', '1000005', 'ALEWarningSign'],
|
||||
\ ['16', '1000006', 'ALEErrorSign'],
|
||||
\ ['2', '1000002', 'ALEWarningSign'],
|
||||
\ ['3', '1000003', 'ALEErrorSign'],
|
||||
\ ['4', '1000004', 'ALEWarningSign'],
|
||||
\ ],
|
||||
\ sort(ParseSigns())
|
||||
|
||||
Execute(No excpetions should be thrown when setting signs for invalid buffers):
|
||||
call ale#sign#SetSigns(123456789, [{'lnum': 15, 'col': 2, 'type': 'W', 'text': 'e'}])
|
||||
|
Loading…
Reference in New Issue
Block a user