summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-10-12 23:04:46 +0100
committerw0rp <devw0rp@gmail.com>2017-10-12 23:04:54 +0100
commite71c4a8bea25e6998d4d852677790ad6bd5a7e68 (patch)
tree16f873ea882322768185a3b1a9ca1b3d1f9ee41e
parentdded246aba9c054e4b91748cd4269c6cda2a03df (diff)
downloadale-e71c4a8bea25e6998d4d852677790ad6bd5a7e68.zip
#965 - Support limiting the number of signs ALE will set
-rw-r--r--autoload/ale/sign.vim20
-rw-r--r--doc/ale.txt19
-rw-r--r--plugin/ale.vim3
-rw-r--r--test/sign/test_sign_limits.vader57
4 files changed, 96 insertions, 3 deletions
diff --git a/autoload/ale/sign.vim b/autoload/ale/sign.vim
index dc3c1109..1c439bc8 100644
--- a/autoload/ale/sign.vim
+++ b/autoload/ale/sign.vim
@@ -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,
diff --git a/doc/ale.txt b/doc/ale.txt
index d202a264..817191f5 100644
--- a/doc/ale.txt
+++ b/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*
diff --git a/plugin/ale.vim b/plugin/ale.vim
index a9ab88a1..2f188d2d 100644
--- a/plugin/ale.vim
+++ b/plugin/ale.vim
@@ -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.
diff --git a/test/sign/test_sign_limits.vader b/test/sign/test_sign_limits.vader
new file mode 100644
index 00000000..b8868aeb
--- /dev/null
+++ b/test/sign/test_sign_limits.vader
@@ -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)