mirror of https://github.com/dense-analysis/ale
#965 - Support limiting the number of signs ALE will set
This commit is contained in:
parent
dded246aba
commit
e71c4a8bea
|
@ -209,7 +209,17 @@ function! s:UpdateLineNumbers(buffer, current_sign_list, loclist) abort
|
|||
endif
|
||||
endfunction
|
||||
|
||||
function! s:BuildSignMap(current_sign_list, grouped_items) abort
|
||||
function! s:BuildSignMap(buffer, current_sign_list, grouped_items) abort
|
||||
let l:max_signs = ale#Var(a:buffer, 'max_signs')
|
||||
|
||||
if l:max_signs is 0
|
||||
let l:selected_grouped_items = []
|
||||
elseif type(l:max_signs) is type(0) && l:max_signs > 0
|
||||
let l:selected_grouped_items = a:grouped_items[:l:max_signs - 1]
|
||||
else
|
||||
let l:selected_grouped_items = a:grouped_items
|
||||
endif
|
||||
|
||||
let l:sign_map = {}
|
||||
let l:sign_offset = g:ale_sign_offset
|
||||
|
||||
|
@ -235,7 +245,7 @@ function! s:BuildSignMap(current_sign_list, grouped_items) abort
|
|||
let l:sign_map[l:line] = l:sign_info
|
||||
endfor
|
||||
|
||||
for l:group in a:grouped_items
|
||||
for l:group in l:selected_grouped_items
|
||||
let l:line = l:group[0].lnum
|
||||
let l:sign_info = get(l:sign_map, l:line, {
|
||||
\ 'current_id_list': [],
|
||||
|
@ -346,7 +356,11 @@ function! ale#sign#SetSigns(buffer, loclist) abort
|
|||
let l:grouped_items = s:GroupLoclistItems(a:buffer, a:loclist)
|
||||
|
||||
" Build a map of current and new signs, with the lines as the keys.
|
||||
let l:sign_map = s:BuildSignMap(l:current_sign_list, l:grouped_items)
|
||||
let l:sign_map = s:BuildSignMap(
|
||||
\ a:buffer,
|
||||
\ l:current_sign_list,
|
||||
\ l:grouped_items,
|
||||
\)
|
||||
|
||||
let l:command_list = ale#sign#GetSignCommands(
|
||||
\ a:buffer,
|
||||
|
|
19
doc/ale.txt
19
doc/ale.txt
|
@ -859,6 +859,23 @@ g:ale_max_buffer_history_size *g:ale_max_buffer_history_size*
|
|||
History can be disabled completely with |g:ale_history_enabled|.
|
||||
|
||||
|
||||
g:ale_max_signs *g:ale_max_signs*
|
||||
*b:ale_max_signs*
|
||||
Type: |Number|
|
||||
Default: `-1`
|
||||
|
||||
When set to any positive integer, ALE will not render any more than the
|
||||
given number of signs for any one buffer.
|
||||
|
||||
When set to `0`, no signs will be set, but sign processing will still be
|
||||
done, so existing signs can be removed.
|
||||
|
||||
When set to any other value, no limit will be imposed on the number of signs
|
||||
set.
|
||||
|
||||
For disabling sign processing, see |g:ale_set_signs|.
|
||||
|
||||
|
||||
g:ale_maximum_file_size *g:ale_maximum_file_size*
|
||||
*b:ale_maximum_file_size*
|
||||
Type: |Number|
|
||||
|
@ -1006,6 +1023,8 @@ g:ale_set_signs *g:ale_set_signs*
|
|||
When multiple problems exist on the same line, the signs will take
|
||||
precedence in the order above, from highest to lowest.
|
||||
|
||||
To limit the number of signs ALE will set, see |g:ale_max_signs|.
|
||||
|
||||
|
||||
g:ale_sign_column_always *g:ale_sign_column_always*
|
||||
|
||||
|
|
|
@ -118,6 +118,9 @@ call ale#Set('list_window_size', 10)
|
|||
" This flag can be set to 0 to disable setting signs.
|
||||
" This is enabled by default only if the 'signs' feature exists.
|
||||
let g:ale_set_signs = get(g:, 'ale_set_signs', has('signs'))
|
||||
" This flag can be set to some integer to control the maximum number of signs
|
||||
" that ALE will set.
|
||||
let g:ale_max_signs = get(g:, 'ale_max_signs', -1)
|
||||
|
||||
" This flag can be set to 1 to enable changing the sign column colors when
|
||||
" there are errors.
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
Before:
|
||||
Save g:ale_max_signs
|
||||
|
||||
let g:ale_max_signs = -1
|
||||
|
||||
function! SetNProblems(sign_count)
|
||||
let l:loclist = []
|
||||
let l:range = range(1, a:sign_count)
|
||||
call setline(1, l:range)
|
||||
|
||||
for l:index in l:range
|
||||
call add(l:loclist, {
|
||||
\ 'bufnr': bufnr(''),
|
||||
\ 'lnum': l:index,
|
||||
\ 'col': 1,
|
||||
\ 'type': 'E',
|
||||
\ 'text': 'a',
|
||||
\})
|
||||
endfor
|
||||
|
||||
call ale#sign#SetSigns(bufnr(''), l:loclist)
|
||||
|
||||
return sort(map(ale#sign#FindCurrentSigns(bufnr(''))[1], 'v:val[0]'), 'n')
|
||||
endfunction
|
||||
|
||||
After:
|
||||
Restore
|
||||
|
||||
unlet! b:ale_max_signs
|
||||
|
||||
delfunction SetNProblems
|
||||
|
||||
sign unplace *
|
||||
|
||||
Execute(There should be no limit on signs with negative numbers):
|
||||
AssertEqual range(1, 42), SetNProblems(42)
|
||||
|
||||
Execute(0 signs should be set when the max is 0):
|
||||
let g:ale_max_signs = 0
|
||||
|
||||
AssertEqual [], SetNProblems(42)
|
||||
|
||||
Execute(1 signs should be set when the max is 1):
|
||||
let g:ale_max_signs = 1
|
||||
|
||||
AssertEqual [1], SetNProblems(42)
|
||||
|
||||
Execute(10 signs should be set when the max is 10):
|
||||
let g:ale_max_signs = 10
|
||||
|
||||
" We'll check that we set signs for the first 10 items, not other lines.
|
||||
AssertEqual range(1, 10), SetNProblems(42)
|
||||
|
||||
Execute(5 signs should be set when the max is 5 for the buffer):
|
||||
let b:ale_max_signs = 5
|
||||
|
||||
AssertEqual range(1, 5), SetNProblems(42)
|
Loading…
Reference in New Issue