#333 Save sign IDs back on loclist items, and make it possible to get line numbers again

This commit is contained in:
w0rp 2017-03-11 20:33:29 +00:00
parent ca78e4c150
commit 4bf6784d7d
4 changed files with 53 additions and 50 deletions

View File

@ -28,7 +28,7 @@ function! ale#sign#ReadSigns(buffer) abort
return split(l:output, "\n") return split(l:output, "\n")
endfunction endfunction
" Given a list of lines for sign output, return a list of sign IDs " Given a list of lines for sign output, return a List of pairs [line, id]
function! ale#sign#ParseSigns(line_list) abort function! ale#sign#ParseSigns(line_list) abort
" Matches output like : " Matches output like :
" line=4 id=1 name=ALEErrorSign " line=4 id=1 name=ALEErrorSign
@ -36,20 +36,19 @@ function! ale#sign#ParseSigns(line_list) abort
" 行=1 識別子=1000001 名前=ALEWarningSign " 行=1 識別子=1000001 名前=ALEWarningSign
" línea=12 id=1000001 nombre=ALEWarningSign " línea=12 id=1000001 nombre=ALEWarningSign
" riga=1 id=1000001, nome=ALEWarningSign " riga=1 id=1000001, nome=ALEWarningSign
let l:pattern = '^.*=\d*\s\+.*=\(\d\+\)\,\?\s\+.*=ALE\(Warning\|Error\|Dummy\)Sign' let l:pattern = '^.*=\(\d\+\).*=\(\d\+\).*=ALE\(Error\|Warning\|Dummy\)Sign'
let l:result = []
let l:id_list = []
for l:line in a:line_list for l:line in a:line_list
let l:match = matchlist(l:line, l:pattern) let l:match = matchlist(l:line, l:pattern)
if len(l:match) > 0 if len(l:match) > 0
call add(l:id_list, l:match[1] + 0) call add(l:result, [str2nr(l:match[1]), str2nr(l:match[2])])
endif endif
endfor endfor
return l:id_list return l:result
endfunction endfunction
function! ale#sign#FindCurrentSigns(buffer) abort function! ale#sign#FindCurrentSigns(buffer) abort
@ -58,54 +57,46 @@ function! ale#sign#FindCurrentSigns(buffer) abort
return ale#sign#ParseSigns(l:line_list) return ale#sign#ParseSigns(l:line_list)
endfunction endfunction
" Given a loclist, combine the loclist into a list of signs such that only " Given a loclist, group the List into with one List per line.
" one sign appears per line. Error lines will take precedence. function! s:GroupSigns(loclist) abort
" The loclist will have been previously sorted.
function! ale#sign#CombineSigns(loclist) abort
let l:signlist = [] let l:signlist = []
let l:last_lnum = -1
for l:obj in a:loclist for l:obj in a:loclist
let l:should_append = 1 " Create a new sub-List when we hit a new line.
if l:obj.lnum != l:last_lnum
if l:obj.lnum < 1 call add(l:signlist, [])
" Skip warnings and errors at line 0, etc.
continue
endif endif
if len(l:signlist) > 0 && l:signlist[-1].lnum == l:obj.lnum call add(l:signlist[-1], l:obj)
" We can't add the same line twice, because signs must be let l:last_lnum = l:obj.lnum
" unique per line.
let l:should_append = 0
if l:signlist[-1].type ==# 'W' && l:obj.type ==# 'E'
" If we had a warning previously, but now have an error,
" we replace the object to set an error instead.
let l:signlist[-1] = l:obj
endif
endif
if l:should_append
call add(l:signlist, l:obj)
endif
endfor endfor
return l:signlist return l:signlist
endfunction endfunction
function! s:IsDummySignSet(current_id_list) abort
for [l:line, l:id] in a:current_id_list
if l:id == g:ale_sign_offset
return 1
endif
if l:line > 1
return 0
endif
endfor
return 0
endfunction
" This function will set the signs which show up on the left. " This function will set the signs which show up on the left.
function! ale#sign#SetSigns(buffer, loclist) abort function! ale#sign#SetSigns(buffer, loclist) abort
let l:signlist = ale#sign#CombineSigns(a:loclist) let l:signlist = s:GroupSigns(a:loclist)
" Find the current markers " Find the current markers
let l:current_id_list = ale#sign#FindCurrentSigns(a:buffer) let l:current_id_list = ale#sign#FindCurrentSigns(a:buffer)
let l:dummy_sign_set = 0
" Check if we set the dummy sign already. " Check if we set the dummy sign already.
for l:current_id in l:current_id_list let l:dummy_sign_set = s:IsDummySignSet(l:current_id_list)
if l:current_id == g:ale_sign_offset
let l:dummy_sign_set = 1
endif
endfor
" If we haven't already set a dummy sign, and we have some previous signs " If we haven't already set a dummy sign, and we have some previous signs
" or always want a dummy sign, then set one, to keep the sign column open. " or always want a dummy sign, then set one, to keep the sign column open.
@ -119,7 +110,7 @@ function! ale#sign#SetSigns(buffer, loclist) abort
" Now remove the previous signs. The dummy will hold the column open " Now remove the previous signs. The dummy will hold the column open
" while we add the new signs, if we had signs before. " while we add the new signs, if we had signs before.
for l:current_id in l:current_id_list for [l:line, l:current_id] in l:current_id_list
if l:current_id != g:ale_sign_offset if l:current_id != g:ale_sign_offset
exec 'sign unplace ' . l:current_id . ' buffer=' . a:buffer exec 'sign unplace ' . l:current_id . ' buffer=' . a:buffer
endif endif
@ -127,11 +118,21 @@ function! ale#sign#SetSigns(buffer, loclist) abort
" Add the new signs, " Add the new signs,
for l:index in range(0, len(l:signlist) - 1) for l:index in range(0, len(l:signlist) - 1)
let l:sign = l:signlist[l:index] let l:sign_id = l:index + g:ale_sign_offset + 1
let l:type = l:sign['type'] ==# 'W' ? 'ALEWarningSign' : 'ALEErrorSign' let l:sublist = l:signlist[l:index]
let l:type = !empty(filter(copy(l:sublist), 'v:val.type ==# ''E'''))
\ ? 'ALEErrorSign'
\ : 'ALEWarningSign'
let l:sign_line = 'sign place ' . (l:index + g:ale_sign_offset + 1) " Save the sign IDs we are setting back on our loclist objects.
\. ' line=' . l:sign['lnum'] " These IDs can be used later for changing line numbers of items
" we keep, based on what Vim adjusts automatically.
for l:obj in l:sublist
let l:obj.sign_id = l:sign_id
endfor
let l:sign_line = 'sign place ' . l:sign_id
\. ' line=' . l:sublist[0].lnum
\. ' name=' . l:type \. ' name=' . l:type
\. ' buffer=' . a:buffer \. ' buffer=' . a:buffer

View File

@ -1,14 +1,14 @@
Execute (Parsing English signs should work): Execute (Parsing English signs should work):
AssertEqual [1000001], ale#sign#ParseSigns(['Signs for app.js:', ' line=9 id=1000001 name=ALEWarningSign']) AssertEqual [[9, 1000001]], ale#sign#ParseSigns(['Signs for app.js:', ' line=9 id=1000001 name=ALEWarningSign'])
Execute (Parsing Russian signs should work): Execute (Parsing Russian signs should work):
AssertEqual [1000001], ale#sign#ParseSigns([' строка=1 id=1000001 имя=ALEErrorSign']) AssertEqual [[1, 1000001]], ale#sign#ParseSigns([' строка=1 id=1000001 имя=ALEErrorSign'])
Execute (Parsing Japanese signs should work): Execute (Parsing Japanese signs should work):
AssertEqual [1000001], ale#sign#ParseSigns([' 行=1 識別子=1000001 名前=ALEWarningSign']) AssertEqual [[1, 1000001]], ale#sign#ParseSigns([' 行=1 識別子=1000001 名前=ALEWarningSign'])
Execute (Parsing Spanish signs should work): Execute (Parsing Spanish signs should work):
AssertEqual [1000001], ale#sign#ParseSigns([' línea=12 id=1000001 nombre=ALEWarningSign']) AssertEqual [[12, 1000001]], ale#sign#ParseSigns([' línea=12 id=1000001 nombre=ALEWarningSign'])
Execute (Parsing Italian signs should work): Execute (Parsing Italian signs should work):
AssertEqual [1000001], ale#sign#ParseSigns([' riga=1 id=1000001, nome=ALEWarningSign']) AssertEqual [[1, 1000001]], ale#sign#ParseSigns([' riga=1 id=1000001, nome=ALEWarningSign'])

View File

@ -85,7 +85,7 @@ Execute(ALEToggle should reset everything and then run again):
" First check that everything is there... " First check that everything is there...
AssertEqual g:expected_loclist, getloclist(0) AssertEqual g:expected_loclist, getloclist(0)
AssertEqual [1000001], ale#sign#FindCurrentSigns(bufnr('%')) AssertEqual [[2, 1000001]], ale#sign#FindCurrentSigns(bufnr('%'))
AssertEqual AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}], \ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}') \ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')
@ -105,7 +105,7 @@ Execute(ALEToggle should reset everything and then run again):
call ale#engine#WaitForJobs(2000) call ale#engine#WaitForJobs(2000)
AssertEqual g:expected_loclist, getloclist(0) AssertEqual g:expected_loclist, getloclist(0)
AssertEqual [1000001], ale#sign#FindCurrentSigns(bufnr('%')) AssertEqual [[2, 1000001]], ale#sign#FindCurrentSigns(bufnr('%'))
AssertEqual AssertEqual
\ [{'group': 'ALEError', 'pos1': [2, 3, 1]}], \ [{'group': 'ALEError', 'pos1': [2, 3, 1]}],
\ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}') \ map(getmatches(), '{''group'': v:val.group, ''pos1'': v:val.pos1}')

View File

@ -13,6 +13,7 @@ Before:
\ 'type': 'W', \ 'type': 'W',
\ 'col': 10, \ 'col': 10,
\ 'text': 'Infix operators must be spaced. [Warning/space-infix-ops]', \ 'text': 'Infix operators must be spaced. [Warning/space-infix-ops]',
\ 'sign_id': 1000001,
\ }, \ },
\ { \ {
\ 'lnum': 2, \ 'lnum': 2,
@ -23,6 +24,7 @@ Before:
\ 'type': 'E', \ 'type': 'E',
\ 'col': 10, \ 'col': 10,
\ 'text': 'Missing semicolon. [Error/semi]', \ 'text': 'Missing semicolon. [Error/semi]',
\ 'sign_id': 1000002,
\ } \ }
\] \]