From ae6cecabb682a2dab04351e7cfd572f465bca3bb Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 13 Aug 2017 13:24:10 +0100 Subject: [PATCH] #653 Filter items based on the buffer number for problem counts --- autoload/ale/statusline.vim | 5 ++- test/test_statusline.vader | 82 +++++++++++++++++++++---------------- 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):