From c6d11f4281e3c3090b2633e234acf437e168d415 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 13 Aug 2017 13:02:59 +0100 Subject: [PATCH] #653 - Filter out other buffers for loclist jumping --- autoload/ale/loclist_jumping.vim | 21 ++++++++++++++++----- test/test_loclist_jumping.vader | 8 ++++++-- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/autoload/ale/loclist_jumping.vim b/autoload/ale/loclist_jumping.vim index 07334b92..42464525 100644 --- a/autoload/ale/loclist_jumping.vim +++ b/autoload/ale/loclist_jumping.vim @@ -10,15 +10,19 @@ " List will be returned, otherwise a pair of [line_number, column_number] will " be returned. function! ale#loclist_jumping#FindNearest(direction, wrap) abort + let l:buffer = bufnr('') let l:pos = getcurpos() let l:info = get(g:ale_buffer_info, bufnr('%'), {'loclist': []}) " This list will have already been sorted. let l:loclist = l:info.loclist - let l:search_item = {'bufnr': bufnr(''), 'lnum': l:pos[1], 'col': l:pos[2]} + let l:search_item = {'bufnr': l:buffer, 'lnum': l:pos[1], 'col': l:pos[2]} + + " Copy the List and filter it to only items in this buffer. + let l:loclist = filter(copy(l:loclist), 'v:val.bufnr == l:buffer') " When searching backwards, so we can find the next smallest match. if a:direction is# 'before' - let l:loclist = reverse(copy(l:loclist)) + let l:loclist = reverse(l:loclist) endif " Look for items before or after the current position. @@ -30,9 +34,12 @@ function! ale#loclist_jumping#FindNearest(direction, wrap) abort " cursor to a line without changing the column, in some cases. let l:cmp_value = ale#util#LocItemCompare( \ { - \ 'bufnr': bufnr(''), + \ 'bufnr': l:buffer, \ 'lnum': l:item.lnum, - \ 'col': min([max([l:item.col, 1]), max([len(getline(l:item.lnum)), 1])]), + \ 'col': min([ + \ max([l:item.col, 1]), + \ max([len(getline(l:item.lnum)), 1]), + \ ]), \ }, \ l:search_item \) @@ -67,13 +74,17 @@ function! ale#loclist_jumping#Jump(direction, wrap) abort endfunction function! ale#loclist_jumping#JumpToIndex(index) abort - let l:info = get(g:ale_buffer_info, bufnr('%'), {'loclist': []}) + let l:buffer = bufnr('') + let l:info = get(g:ale_buffer_info, l:buffer, {'loclist': []}) let l:loclist = l:info.loclist + let l:loclist = filter(copy(l:loclist), 'v:val.bufnr == l:buffer') + if empty(l:loclist) return endif let l:item = l:loclist[a:index] + if !empty(l:item) call cursor([l:item.lnum, l:item.col]) endif diff --git a/test/test_loclist_jumping.vader b/test/test_loclist_jumping.vader index da167677..5e18499e 100644 --- a/test/test_loclist_jumping.vader +++ b/test/test_loclist_jumping.vader @@ -1,7 +1,8 @@ Before: let g:ale_buffer_info = { - \ bufnr('%'): { + \ bufnr(''): { \ 'loclist': [ + \ {'bufnr': bufnr('') - 1, 'lnum': 3, 'col': 2}, \ {'bufnr': bufnr(''), 'lnum': 1, 'col': 2}, \ {'bufnr': bufnr(''), 'lnum': 1, 'col': 3}, \ {'bufnr': bufnr(''), 'lnum': 2, 'col': 1}, @@ -9,6 +10,7 @@ Before: \ {'bufnr': bufnr(''), 'lnum': 2, 'col': 3}, \ {'bufnr': bufnr(''), 'lnum': 2, 'col': 6}, \ {'bufnr': bufnr(''), 'lnum': 2, 'col': 700}, + \ {'bufnr': bufnr('') + 1, 'lnum': 3, 'col': 2}, \ ], \ }, \} @@ -32,7 +34,6 @@ After: Given foobar (Some imaginary filetype): 12345678 12345678 - Execute(loclist jumping should jump correctly when not wrapping): AssertEqual [2, 1], TestJump('before', 0, [2, 2]) @@ -77,6 +78,9 @@ Execute(We shouldn't move when jumping to the first item where there are none): AssertEqual [1, 6], TestJump(0, 0, [1, 6]) Execute(We should be able to jump when the error line is blank): + " Add a blank line at the end. + call setline(1, getline('.', '$') + ['']) + " Add a problem on the blank line. call add(g:ale_buffer_info[bufnr('%')].loclist, {'bufnr': bufnr(''), 'lnum': 3, 'col': 1}) AssertEqual 0, len(getline(3))