summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-08-13 13:24:10 +0100
committerw0rp <devw0rp@gmail.com>2017-08-13 13:24:10 +0100
commitae6cecabb682a2dab04351e7cfd572f465bca3bb (patch)
treeb374f43d9de117657eeb2b18bed3b8c50ad6def7
parentf67fc43d9b633db2b3d0de728bb4b9e3f9066049 (diff)
downloadale-ae6cecabb682a2dab04351e7cfd572f465bca3bb.zip
#653 Filter items based on the buffer number for problem counts
-rw-r--r--autoload/ale/statusline.vim5
-rw-r--r--test/test_statusline.vader82
2 files changed, 49 insertions, 38 deletions
diff --git a/autoload/ale/statusline.vim b/autoload/ale/statusline.vim
index fd586a23..a073f7a0 100644
--- a/autoload/ale/statusline.vim
+++ b/autoload/ale/statusline.vim
@@ -22,10 +22,11 @@ function! ale#statusline#Update(buffer, loclist) abort
return
endif
+ let l:loclist = filter(copy(a:loclist), 'v:val.bufnr == a:buffer')
let l:count = s:CreateCountDict()
- let l:count.total = len(a:loclist)
+ let l:count.total = len(l:loclist)
- for l:entry in a:loclist
+ for l:entry in l:loclist
if l:entry.type is# 'W'
if get(l:entry, 'sub_type', '') is# 'style'
let l:count.style_warning += 1
diff --git a/test/test_statusline.vader b/test/test_statusline.vader
index bd0fd5dc..c47df75a 100644
--- a/test/test_statusline.vader
+++ b/test/test_statusline.vader
@@ -31,7 +31,7 @@ After:
delfunction Counts
Execute (Count should be 0 when data is empty):
- AssertEqual Counts({}), ale#statusline#Count(bufnr('%'))
+ AssertEqual Counts({}), ale#statusline#Count(bufnr(''))
Execute (Count should read data from the cache):
let g:ale_buffer_info = {'44': {'count': Counts({'error': 1, 'warning': 2})}}
@@ -44,23 +44,33 @@ Execute (The count should be correct after an update):
Execute (Count should be match the loclist):
let g:ale_buffer_info = {
- \ bufnr('%'): {
+ \ bufnr(''): {
\ 'loclist': [
- \ {'type': 'E'},
- \ {'type': 'E', 'sub_type': 'style'},
- \ {'type': 'E', 'sub_type': 'style'},
- \ {'type': 'W'},
- \ {'type': 'W'},
- \ {'type': 'W'},
- \ {'type': 'W', 'sub_type': 'style'},
- \ {'type': 'W', 'sub_type': 'style'},
- \ {'type': 'W', 'sub_type': 'style'},
- \ {'type': 'W', 'sub_type': 'style'},
- \ {'type': 'I'},
- \ {'type': 'I'},
- \ {'type': 'I'},
- \ {'type': 'I'},
- \ {'type': 'I'},
+ \ {'bufnr': bufnr('') - 1, 'type': 'E'},
+ \ {'bufnr': bufnr('') - 1, 'type': 'E', 'sub_type': 'style'},
+ \ {'bufnr': bufnr('') - 1, 'type': 'W'},
+ \ {'bufnr': bufnr('') - 1, 'type': 'W', 'sub_type': 'style'},
+ \ {'bufnr': bufnr('') - 1, 'type': 'I'},
+ \ {'bufnr': bufnr(''), 'type': 'E'},
+ \ {'bufnr': bufnr(''), 'type': 'E', 'sub_type': 'style'},
+ \ {'bufnr': bufnr(''), 'type': 'E', 'sub_type': 'style'},
+ \ {'bufnr': bufnr(''), 'type': 'W'},
+ \ {'bufnr': bufnr(''), 'type': 'W'},
+ \ {'bufnr': bufnr(''), 'type': 'W'},
+ \ {'bufnr': bufnr(''), 'type': 'W', 'sub_type': 'style'},
+ \ {'bufnr': bufnr(''), 'type': 'W', 'sub_type': 'style'},
+ \ {'bufnr': bufnr(''), 'type': 'W', 'sub_type': 'style'},
+ \ {'bufnr': bufnr(''), 'type': 'W', 'sub_type': 'style'},
+ \ {'bufnr': bufnr(''), 'type': 'I'},
+ \ {'bufnr': bufnr(''), 'type': 'I'},
+ \ {'bufnr': bufnr(''), 'type': 'I'},
+ \ {'bufnr': bufnr(''), 'type': 'I'},
+ \ {'bufnr': bufnr(''), 'type': 'I'},
+ \ {'bufnr': bufnr('') + 1, 'type': 'E'},
+ \ {'bufnr': bufnr('') + 1, 'type': 'E', 'sub_type': 'style'},
+ \ {'bufnr': bufnr('') + 1, 'type': 'W'},
+ \ {'bufnr': bufnr('') + 1, 'type': 'W', 'sub_type': 'style'},
+ \ {'bufnr': bufnr('') + 1, 'type': 'I'},
\ ],
\ },
\}
@@ -73,46 +83,46 @@ Execute (Count should be match the loclist):
\ '0': 3,
\ '1': 12,
\ 'total': 15,
- \}, ale#statusline#Count(bufnr('%'))
+ \}, ale#statusline#Count(bufnr(''))
Execute (Output should be empty for non-existant buffer):
AssertEqual Counts({}), ale#statusline#Count(9001)
Execute (Status() should return just errors for the old format):
let g:ale_statusline_format = ['%sE', '%sW', 'OKIE']
- let g:ale_buffer_info = {bufnr('%'): {}}
- call ale#statusline#Update(bufnr('%'), [
- \ {'type': 'E'},
- \ {'type': 'E', 'sub_type': 'style'},
+ let g:ale_buffer_info = {bufnr(''): {}}
+ call ale#statusline#Update(bufnr(''), [
+ \ {'bufnr': bufnr(''), 'type': 'E'},
+ \ {'bufnr': bufnr(''), 'type': 'E', 'sub_type': 'style'},
\])
AssertEqual '2E', ale#statusline#Status()
Execute (Status() should return just warnings for the old format):
let g:ale_statusline_format = ['%sE', '%sW', 'OKIE']
- let g:ale_buffer_info = {bufnr('%'): {}}
- call ale#statusline#Update(bufnr('%'), [
- \ {'type': 'W'},
- \ {'type': 'W', 'sub_type': 'style'},
- \ {'type': 'I'},
+ let g:ale_buffer_info = {bufnr(''): {}}
+ call ale#statusline#Update(bufnr(''), [
+ \ {'bufnr': bufnr(''), 'type': 'W'},
+ \ {'bufnr': bufnr(''), 'type': 'W', 'sub_type': 'style'},
+ \ {'bufnr': bufnr(''), 'type': 'I'},
\])
AssertEqual '3W', ale#statusline#Status()
Execute (Status() should return errors and warnings for the old format):
let g:ale_statusline_format = ['%sE', '%sW', 'OKIE']
- let g:ale_buffer_info = {bufnr('%'): {}}
- call ale#statusline#Update(bufnr('%'), [
- \ {'type': 'E'},
- \ {'type': 'E', 'sub_type': 'style'},
- \ {'type': 'W'},
- \ {'type': 'W', 'sub_type': 'style'},
- \ {'type': 'I'},
+ let g:ale_buffer_info = {bufnr(''): {}}
+ call ale#statusline#Update(bufnr(''), [
+ \ {'bufnr': bufnr(''), 'type': 'E'},
+ \ {'bufnr': bufnr(''), 'type': 'E', 'sub_type': 'style'},
+ \ {'bufnr': bufnr(''), 'type': 'W'},
+ \ {'bufnr': bufnr(''), 'type': 'W', 'sub_type': 'style'},
+ \ {'bufnr': bufnr(''), 'type': 'I'},
\])
AssertEqual '2E 3W', ale#statusline#Status()
Execute (Status() should return the custom 'OK' string with the old format):
let g:ale_statusline_format = ['%sE', '%sW', 'OKIE']
- let g:ale_buffer_info = {bufnr('%'): {}}
- call ale#statusline#Update(bufnr('%'), [])
+ let g:ale_buffer_info = {bufnr(''): {}}
+ call ale#statusline#Update(bufnr(''), [])
AssertEqual 'OKIE', ale#statusline#Status()
Execute(ale#statusline#Update shouldn't blow up when globals are undefined):