569 support vim sign group and priority (#2786)

* Use sign-group only on supported vim versions.

The sign-group feature is only available in nvim 0.4.0 and vim 8.1.614.

* Add priority to ALE signs.

This allows users to set a priority to ALE signs to take precedence over
other plugin signs.
This commit is contained in:
Horacio Sanson 2019-09-25 17:15:16 +09:00 committed by w0rp
parent 6746eaeaa0
commit 41ff80dc9e
11 changed files with 180 additions and 58 deletions

View file

@ -14,6 +14,7 @@ let g:ale_sign_style_error = get(g:, 'ale_sign_style_error', g:ale_sign_error)
let g:ale_sign_warning = get(g:, 'ale_sign_warning', '--') let g:ale_sign_warning = get(g:, 'ale_sign_warning', '--')
let g:ale_sign_style_warning = get(g:, 'ale_sign_style_warning', g:ale_sign_warning) let g:ale_sign_style_warning = get(g:, 'ale_sign_style_warning', g:ale_sign_warning)
let g:ale_sign_info = get(g:, 'ale_sign_info', g:ale_sign_warning) let g:ale_sign_info = get(g:, 'ale_sign_info', g:ale_sign_warning)
let g:ale_sign_priority = get(g:, 'ale_sign_priority', 30)
" This variable sets an offset which can be set for sign IDs. " This variable sets an offset which can be set for sign IDs.
" This ID can be changed depending on what IDs are set for other plugins. " This ID can be changed depending on what IDs are set for other plugins.
" The dummy sign will use the ID exactly equal to the offset. " The dummy sign will use the ID exactly equal to the offset.
@ -147,24 +148,57 @@ function! ale#sign#GetSignName(sublist) abort
return 'ALEErrorSign' return 'ALEErrorSign'
endfunction endfunction
function! s:PriorityCmd() abort
if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
return ' priority=' . g:ale_sign_priority . ' '
else
return ''
endif
endfunction
function! s:GroupCmd() abort
if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
return ' group=ale '
else
return ' '
endif
endfunction
" Read sign data for a buffer to a list of lines. " Read sign data for a buffer to a list of lines.
function! ale#sign#ReadSigns(buffer) abort function! ale#sign#ReadSigns(buffer) abort
redir => l:output redir => l:output
silent execute 'sign place buffer=' . a:buffer silent execute 'sign place ' . s:GroupCmd() . s:PriorityCmd()
\ . ' buffer=' . a:buffer
redir end redir end
return split(l:output, "\n") return split(l:output, "\n")
endfunction endfunction
function! ale#sign#ParsePattern() abort
if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
" Matches output like :
" line=4 id=1 group=ale name=ALEErrorSign
" строка=1 id=1000001 group=ale имя=ALEErrorSign
" 行=1 識別子=1000001 group=ale 名前=ALEWarningSign
" línea=12 id=1000001 group=ale nombre=ALEWarningSign
" riga=1 id=1000001 group=ale nome=ALEWarningSign
let l:pattern = '\v^.*\=(\d+).*\=(\d+).*group\=ale.*\=(ALE[a-zA-Z]+Sign)'
else
" Matches output like :
" line=4 id=1 name=ALEErrorSign
" строка=1 id=1000001 имя=ALEErrorSign
" 行=1 識別子=1000001 名前=ALEWarningSign
" línea=12 id=1000001 nombre=ALEWarningSign
" riga=1 id=1000001 nome=ALEWarningSign
let l:pattern = '\v^.*\=(\d+).*\=(\d+).*\=(ALE[a-zA-Z]+Sign)'
endif
return l:pattern
endfunction
" Given a list of lines for sign output, return a List of [line, id, group] " Given a list of lines for sign output, return a List of [line, id, group]
function! ale#sign#ParseSigns(line_list) abort function! ale#sign#ParseSigns(line_list) abort
" Matches output like : let l:pattern =ale#sign#ParsePattern()
" line=4 id=1 name=ALEErrorSign
" строка=1 id=1000001 имя=ALEErrorSign
" 行=1 識別子=1000001 名前=ALEWarningSign
" línea=12 id=1000001 nombre=ALEWarningSign
" riga=1 id=1000001, nome=ALEWarningSign
let l:pattern = '\v^.*\=(\d+).*\=(\d+).*\=(ALE[a-zA-Z]+Sign)'
let l:result = [] let l:result = []
let l:is_dummy_sign_set = 0 let l:is_dummy_sign_set = 0
@ -319,8 +353,10 @@ function! ale#sign#GetSignCommands(buffer, was_sign_set, sign_map) abort
if !l:is_dummy_sign_set && (!empty(a:sign_map) || g:ale_sign_column_always) if !l:is_dummy_sign_set && (!empty(a:sign_map) || g:ale_sign_column_always)
call add(l:command_list, 'sign place ' call add(l:command_list, 'sign place '
\ . g:ale_sign_offset \ . g:ale_sign_offset
\ . ' line=1 name=ALEDummySign buffer=' \ . s:GroupCmd()
\ . a:buffer \ . s:PriorityCmd()
\ . ' line=1 name=ALEDummySign '
\ . ' buffer=' . a:buffer
\) \)
let l:is_dummy_sign_set = 1 let l:is_dummy_sign_set = 1
endif endif
@ -337,6 +373,8 @@ function! ale#sign#GetSignCommands(buffer, was_sign_set, sign_map) abort
if index(l:info.current_id_list, l:info.new_id) < 0 if index(l:info.current_id_list, l:info.new_id) < 0
call add(l:command_list, 'sign place ' call add(l:command_list, 'sign place '
\ . (l:info.new_id) \ . (l:info.new_id)
\ . s:GroupCmd()
\ . s:PriorityCmd()
\ . ' line=' . l:line_str \ . ' line=' . l:line_str
\ . ' name=' . (l:info.new_name) \ . ' name=' . (l:info.new_name)
\ . ' buffer=' . a:buffer \ . ' buffer=' . a:buffer
@ -351,6 +389,7 @@ function! ale#sign#GetSignCommands(buffer, was_sign_set, sign_map) abort
if l:current_id isnot l:info.new_id if l:current_id isnot l:info.new_id
call add(l:command_list, 'sign unplace ' call add(l:command_list, 'sign unplace '
\ . l:current_id \ . l:current_id
\ . s:GroupCmd()
\ . ' buffer=' . a:buffer \ . ' buffer=' . a:buffer
\) \)
endif endif
@ -361,6 +400,7 @@ function! ale#sign#GetSignCommands(buffer, was_sign_set, sign_map) abort
if l:is_dummy_sign_set && !g:ale_sign_column_always if l:is_dummy_sign_set && !g:ale_sign_column_always
call add(l:command_list, 'sign unplace ' call add(l:command_list, 'sign unplace '
\ . g:ale_sign_offset \ . g:ale_sign_offset
\ . s:GroupCmd()
\ . ' buffer=' . a:buffer \ . ' buffer=' . a:buffer
\) \)
endif endif
@ -415,3 +455,12 @@ function! ale#sign#SetSigns(buffer, loclist) abort
highlight link SignColumn ALESignColumnWithoutErrors highlight link SignColumn ALESignColumnWithoutErrors
endif endif
endfunction endfunction
" Remove all signs.
function! ale#sign#Clear() abort
if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
sign unplace group=ale *
else
sign unplace *
endif
endfunction

View file

@ -1543,6 +1543,16 @@ g:ale_set_signs *g:ale_set_signs*
To limit the number of signs ALE will set, see |g:ale_max_signs|. To limit the number of signs ALE will set, see |g:ale_max_signs|.
g:ale_sign_priority *g:ale_sign_priority*
Type: |Number|
Default: `30`
From Neovim 0.4.0 and Vim 8.1, ALE can set sign priority to all signs. The
larger this value is, the higher priority ALE signs have over other plugin
signs. See |sign-priority| for further details on how priority works.
g:ale_shell *g:ale_shell* g:ale_shell *g:ale_shell*
Type: |String| Type: |String|

View file

@ -21,7 +21,7 @@ Before:
let g:ale_set_highlights = 0 let g:ale_set_highlights = 0
let g:ale_echo_cursor = 0 let g:ale_echo_cursor = 0
sign unplace * call ale#sign#Clear()
function! TestCallback(buffer, output) function! TestCallback(buffer, output)
return [ return [
@ -32,16 +32,20 @@ Before:
function! CollectSigns() function! CollectSigns()
redir => l:output redir => l:output
silent exec 'sign place' if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
silent exec 'sign place group=ale'
else
silent exec 'sign place'
endif
redir END redir END
let l:actual_sign_list = [] let l:actual_sign_list = []
for l:line in split(l:output, "\n") for l:line in split(l:output, "\n")
let l:match = matchlist(l:line, '\v^.*\=(\d+).*\=\d+.*\=(ALE[a-zA-Z]+Sign)') let l:match = matchlist(l:line, ale#sign#ParsePattern())
if len(l:match) > 0 if len(l:match) > 0
call add(l:actual_sign_list, [l:match[1], l:match[2]]) call add(l:actual_sign_list, [l:match[1], l:match[3]])
endif endif
endfor endfor
@ -60,7 +64,7 @@ After:
delfunction CollectSigns delfunction CollectSigns
unlet! g:ale_run_synchronously_callbacks unlet! g:ale_run_synchronously_callbacks
sign unplace * call ale#sign#Clear()
call ale#linter#Reset() call ale#linter#Reset()
Execute(The signs should be updated after linting is done): Execute(The signs should be updated after linting is done):

View file

@ -30,7 +30,7 @@ After:
delfunction SetHighlight delfunction SetHighlight
unlet! g:sign_highlight unlet! g:sign_highlight
sign unplace * call ale#sign#Clear()
Execute(The SignColumn highlight shouldn't be changed if the option is off): Execute(The SignColumn highlight shouldn't be changed if the option is off):
let g:ale_change_sign_column_color = 0 let g:ale_change_sign_column_color = 0

View file

@ -30,7 +30,7 @@ After:
delfunction SetNProblems delfunction SetNProblems
sign unplace * call ale#sign#Clear()
Execute(There should be no limit on signs with negative numbers): Execute(There should be no limit on signs with negative numbers):
AssertEqual range(1, 42), SetNProblems(42) AssertEqual range(1, 42), SetNProblems(42)

View file

@ -1,35 +1,77 @@
Execute (Parsing English signs should work): Execute (Parsing English signs should work):
AssertEqual if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
\ [0, [[9, 1000001, 'ALEWarningSign']]], AssertEqual
\ ale#sign#ParseSigns([ \ [0, [[9, 1000001, 'ALEWarningSign']]],
\ 'Signs for app.js:', \ ale#sign#ParseSigns([
\ ' line=9 id=1000001 name=ALEWarningSign', \ 'Signs for app.js:',
\ ]) \ ' line=9 id=1000001 group=ale name=ALEWarningSign',
\ ])
else
AssertEqual
\ [0, [[9, 1000001, 'ALEWarningSign']]],
\ ale#sign#ParseSigns([
\ 'Signs for app.js:',
\ ' line=9 id=1000001 name=ALEWarningSign',
\ ])
endif
Execute (Parsing Russian signs should work): Execute (Parsing Russian signs should work):
AssertEqual if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
\ [0, [[1, 1000001, 'ALEErrorSign']]], AssertEqual
\ ale#sign#ParseSigns([' строка=1 id=1000001 имя=ALEErrorSign']) \ [0, [[1, 1000001, 'ALEErrorSign']]],
\ ale#sign#ParseSigns([' строка=1 id=1000001 group=ale имя=ALEErrorSign'])
else
AssertEqual
\ [0, [[1, 1000001, 'ALEErrorSign']]],
\ ale#sign#ParseSigns([' строка=1 id=1000001 имя=ALEErrorSign'])
endif
Execute (Parsing Japanese signs should work): Execute (Parsing Japanese signs should work):
AssertEqual if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
\ [0, [[1, 1000001, 'ALEWarningSign']]], AssertEqual
\ ale#sign#ParseSigns([' 行=1 識別子=1000001 名前=ALEWarningSign']) \ [0, [[1, 1000001, 'ALEWarningSign']]],
\ ale#sign#ParseSigns([' 行=1 識別子=1000001 group=ale 名前=ALEWarningSign'])
else
AssertEqual
\ [0, [[1, 1000001, 'ALEWarningSign']]],
\ ale#sign#ParseSigns([' 行=1 識別子=1000001 名前=ALEWarningSign'])
endif
Execute (Parsing Spanish signs should work): Execute (Parsing Spanish signs should work):
AssertEqual if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
\ [0, [[12, 1000001, 'ALEWarningSign']]], AssertEqual
\ ale#sign#ParseSigns([' línea=12 id=1000001 nombre=ALEWarningSign']) \ [0, [[12, 1000001, 'ALEWarningSign']]],
\ ale#sign#ParseSigns([' línea=12 id=1000001 group=ale nombre=ALEWarningSign'])
else
AssertEqual
\ [0, [[12, 1000001, 'ALEWarningSign']]],
\ ale#sign#ParseSigns([' línea=12 id=1000001 nombre=ALEWarningSign'])
endif
Execute (Parsing Italian signs should work): Execute (Parsing Italian signs should work):
AssertEqual if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
\ [0, [[1, 1000001, 'ALEWarningSign']]], AssertEqual
\ ale#sign#ParseSigns([' riga=1 id=1000001, nome=ALEWarningSign']) \ [0, [[1, 1000001, 'ALEWarningSign']]],
\ \ ale#sign#ParseSigns([' riga=1 id=1000001, group=ale nome=ALEWarningSign'])
else
AssertEqual
\ [0, [[1, 1000001, 'ALEWarningSign']]],
\ ale#sign#ParseSigns([' riga=1 id=1000001, nome=ALEWarningSign'])
endif
Execute (The sign parser should indicate if the dummy sign is set): Execute (The sign parser should indicate if the dummy sign is set):
AssertEqual if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
\ [1, [[1, 1000001, 'ALEErrorSign']]], AssertEqual
\ ale#sign#ParseSigns([ \ [1, [[1, 1000001, 'ALEErrorSign']]],
\ ' строка=1 id=1000001 имя=ALEErrorSign', \ ale#sign#ParseSigns([
\ ' line=1 id=1000000 name=ALEDummySign', \ ' строка=1 id=1000001 group=ale имя=ALEErrorSign',
\ ]) \ ' line=1 id=1000000 group=ale name=ALEDummySign',
\ ])
else
AssertEqual
\ [1, [[1, 1000001, 'ALEErrorSign']]],
\ ale#sign#ParseSigns([
\ ' строка=1 id=1000001 имя=ALEErrorSign',
\ ' line=1 id=1000000 name=ALEDummySign',
\ ])
endif

View file

@ -17,7 +17,7 @@ Before:
let g:ale_echo_cursor = 0 let g:ale_echo_cursor = 0
call ale#linter#Reset() call ale#linter#Reset()
sign unplace * call ale#sign#Clear()
function! GenerateResults(buffer, output) function! GenerateResults(buffer, output)
return [ return [
@ -68,12 +68,16 @@ Before:
function! ParseSigns() function! ParseSigns()
redir => l:output redir => l:output
silent sign place if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
silent sign place group=ale
else
silent sign place
endif
redir END redir END
return map( return map(
\ split(l:output, '\n')[2:], \ split(l:output, '\n')[2:],
\ 'matchlist(v:val, ''^.*=\(\d\+\).*=\(\d\+\).*=\(.*\)$'')[1:3]', \ 'matchlist(v:val, ''' . ale#sign#ParsePattern() . ''')[1:3]',
\) \)
endfunction endfunction
@ -92,7 +96,7 @@ After:
delfunction GenerateResults delfunction GenerateResults
delfunction ParseSigns delfunction ParseSigns
call ale#linter#Reset() call ale#linter#Reset()
sign unplace * call ale#sign#Clear()
Execute(ale#sign#GetSignName should return the right sign names): Execute(ale#sign#GetSignName should return the right sign names):
AssertEqual 'ALEErrorSign', ale#sign#GetSignName([{'type': 'E'}]) AssertEqual 'ALEErrorSign', ale#sign#GetSignName([{'type': 'E'}])
@ -148,9 +152,15 @@ Execute(The current signs should be set for running a job):
\ ParseSigns() \ ParseSigns()
Execute(Loclist items with sign_id values should be kept): Execute(Loclist items with sign_id values should be kept):
exec 'sign place 1000347 line=3 name=ALEErrorSign buffer=' . bufnr('') if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
exec 'sign place 1000348 line=15 name=ALEErrorSign buffer=' . bufnr('') exec 'sign place 1000347 group=ale line=3 name=ALEErrorSign buffer=' . bufnr('')
exec 'sign place 1000349 line=16 name=ALEWarningSign buffer=' . bufnr('') exec 'sign place 1000348 group=ale line=15 name=ALEErrorSign buffer=' . bufnr('')
exec 'sign place 1000349 group=ale line=16 name=ALEWarningSign buffer=' . bufnr('')
else
exec 'sign place 1000347 line=3 name=ALEErrorSign buffer=' . bufnr('')
exec 'sign place 1000348 line=15 name=ALEErrorSign buffer=' . bufnr('')
exec 'sign place 1000349 line=16 name=ALEWarningSign buffer=' . bufnr('')
endif
let g:loclist = [ let g:loclist = [
\ {'bufnr': bufnr(''), 'lnum': 1, 'col': 1, 'type': 'E', 'text': 'a', 'sign_id': 1000348}, \ {'bufnr': bufnr(''), 'lnum': 1, 'col': 1, 'type': 'E', 'text': 'a', 'sign_id': 1000348},
@ -287,10 +297,17 @@ Execute(No exceptions should be thrown when setting signs for invalid buffers):
Execute(Signs should be removed when lines have multiple sign IDs on them): Execute(Signs should be removed when lines have multiple sign IDs on them):
" We can fail to remove signs if there are multiple signs on one line, " We can fail to remove signs if there are multiple signs on one line,
" say after deleting lines in Vim, etc. " say after deleting lines in Vim, etc.
exec 'sign place 1000347 line=3 name=ALEErrorSign buffer=' . bufnr('') if has('nvim-0.4.0') || (v:version >= 801 && has('patch614'))
exec 'sign place 1000348 line=3 name=ALEWarningSign buffer=' . bufnr('') exec 'sign place 1000347 group=ale line=3 name=ALEErrorSign buffer=' . bufnr('')
exec 'sign place 1000349 line=10 name=ALEErrorSign buffer=' . bufnr('') exec 'sign place 1000348 group=ale line=3 name=ALEWarningSign buffer=' . bufnr('')
exec 'sign place 1000350 line=10 name=ALEWarningSign buffer=' . bufnr('') exec 'sign place 1000349 group=ale line=10 name=ALEErrorSign buffer=' . bufnr('')
exec 'sign place 1000350 group=ale line=10 name=ALEWarningSign buffer=' . bufnr('')
else
exec 'sign place 1000347 line=3 name=ALEErrorSign buffer=' . bufnr('')
exec 'sign place 1000348 line=3 name=ALEWarningSign buffer=' . bufnr('')
exec 'sign place 1000349 line=10 name=ALEErrorSign buffer=' . bufnr('')
exec 'sign place 1000350 line=10 name=ALEWarningSign buffer=' . bufnr('')
endif
call ale#sign#SetSigns(bufnr(''), []) call ale#sign#SetSigns(bufnr(''), [])
AssertEqual [], ParseSigns() AssertEqual [], ParseSigns()

View file

@ -82,7 +82,7 @@ Before:
\ 'read_buffer': 0, \ 'read_buffer': 0,
\}) \})
sign unplace * call ale#sign#Clear()
After: After:
Restore Restore
@ -105,7 +105,7 @@ After:
delfunction ParseAuGroups delfunction ParseAuGroups
call setloclist(0, []) call setloclist(0, [])
sign unplace * call ale#sign#Clear()
call clearmatches() call clearmatches()
Given foobar (Some imaginary filetype): Given foobar (Some imaginary filetype):

View file

@ -114,7 +114,7 @@ After:
delfunction GenerateResults delfunction GenerateResults
call ale#linter#Reset() call ale#linter#Reset()
call clearmatches() call clearmatches()
sign unplace * call ale#sign#Clear()
highlight clear SomeOtherGroup highlight clear SomeOtherGroup
runtime autoload/ale/highlight.vim runtime autoload/ale/highlight.vim

View file

@ -8,7 +8,7 @@ After:
call setloclist(0, []) call setloclist(0, [])
call clearmatches() call clearmatches()
sign unplace * call ale#sign#Clear()
Given foobar (Some file): Given foobar (Some file):
abc abc

View file

@ -38,7 +38,7 @@ After:
" Items and markers, etc. " Items and markers, etc.
call setloclist(0, []) call setloclist(0, [])
call clearmatches() call clearmatches()
sign unplace * call ale#sign#Clear()
Given foobar(A file with some lines): Given foobar(A file with some lines):
foo foo