#314 filter both lists, and add tests to cover the list retrieval
This commit is contained in:
parent
1a9c8b8d06
commit
c310080359
@ -2,19 +2,20 @@
|
|||||||
" Description: This file implements functions for jumping around in a file
|
" Description: This file implements functions for jumping around in a file
|
||||||
" based on errors and warnings in the loclist or quickfix list.
|
" based on errors and warnings in the loclist or quickfix list.
|
||||||
|
|
||||||
function! s:GetCurrentList() abort
|
function! s:GetCurrentList() abort
|
||||||
if g:ale_set_loclist
|
let l:buffer = bufnr('%')
|
||||||
return getloclist(winnr())
|
let l:list = []
|
||||||
elseif g:ale_set_quickfix
|
|
||||||
let l:buffer = bufnr('%')
|
|
||||||
|
|
||||||
return filter(getqflist(), 'get(v:val, ''bufnr'', -1) == ' . l:buffer)
|
if g:ale_set_loclist
|
||||||
|
let l:list = getloclist(winnr())
|
||||||
|
elseif g:ale_set_quickfix
|
||||||
|
let l:list = getqflist()
|
||||||
endif
|
endif
|
||||||
|
|
||||||
return []
|
return filter(l:list, 'get(v:val, ''bufnr'', -1) == ' . l:buffer)
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! s:GetSortedLoclist() abort
|
function! ale#loclist_jumping#GetSortedList() abort
|
||||||
let l:loclist = []
|
let l:loclist = []
|
||||||
|
|
||||||
for l:item in s:GetCurrentList()
|
for l:item in s:GetCurrentList()
|
||||||
@ -41,7 +42,7 @@ endfunction
|
|||||||
" List will be returned, otherwise a pair of [line_number, column_number] will
|
" List will be returned, otherwise a pair of [line_number, column_number] will
|
||||||
" be returned.
|
" be returned.
|
||||||
function! ale#loclist_jumping#FindNearest(direction, wrap) abort
|
function! ale#loclist_jumping#FindNearest(direction, wrap) abort
|
||||||
let l:loclist = s:GetSortedLoclist()
|
let l:loclist = ale#loclist_jumping#GetSortedList()
|
||||||
|
|
||||||
if empty(l:loclist)
|
if empty(l:loclist)
|
||||||
" We couldn't find anything, so stop here.
|
" We couldn't find anything, so stop here.
|
||||||
|
74
test/test_loclist_jumping_loading.vader
Normal file
74
test/test_loclist_jumping_loading.vader
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
Before:
|
||||||
|
let g:buffer = bufnr('%')
|
||||||
|
|
||||||
|
function! GetList() abort
|
||||||
|
return map(
|
||||||
|
\ ale#loclist_jumping#GetSortedList(),
|
||||||
|
\ '{''lnum'': v:val.lnum, ''col'': v:val.col, ''text'': v:val.text}'
|
||||||
|
\)
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
After:
|
||||||
|
unlet! g:buffer
|
||||||
|
unlet! g:new_buffer
|
||||||
|
let g:ale_set_loclist = 1
|
||||||
|
let g:ale_set_quickfix = 0
|
||||||
|
call setloclist(winnr(), [])
|
||||||
|
call setqflist([])
|
||||||
|
delfunction GetList
|
||||||
|
|
||||||
|
Execute(The loclist should be filtered and sorted appropriately for jumping):
|
||||||
|
:new
|
||||||
|
|
||||||
|
let g:new_buffer = bufnr('%')
|
||||||
|
|
||||||
|
AssertNotEqual g:new_buffer, g:buffer
|
||||||
|
|
||||||
|
call setloclist(winnr(), [
|
||||||
|
\ {'lnum': 1, 'col': 1, 'text': 'ignore this', 'bufnr': g:buffer},
|
||||||
|
\ {'lnum': 20, 'col': 5, 'text': 'baz', 'bufnr': g:new_buffer},
|
||||||
|
\ {'lnum': 10, 'col': 6, 'text': 'bar', 'bufnr': g:new_buffer},
|
||||||
|
\ {'lnum': 10, 'col': 5, 'text': 'foo', 'bufnr': g:new_buffer},
|
||||||
|
\])
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {'lnum': 10, 'col': 5, 'text': 'foo'},
|
||||||
|
\ {'lnum': 10, 'col': 6, 'text': 'bar'},
|
||||||
|
\ {'lnum': 20, 'col': 5, 'text': 'baz'},
|
||||||
|
\ ],
|
||||||
|
\ GetList()
|
||||||
|
|
||||||
|
Execute(quickfix should be filtered and sorted appropriately for jumping):
|
||||||
|
let g:ale_set_loclist = 0
|
||||||
|
let g:ale_set_quickfix = 1
|
||||||
|
|
||||||
|
:new
|
||||||
|
|
||||||
|
let g:new_buffer = bufnr('%')
|
||||||
|
|
||||||
|
AssertNotEqual g:new_buffer, g:buffer
|
||||||
|
|
||||||
|
call setqflist([
|
||||||
|
\ {'lnum': 1, 'col': 1, 'text': 'ignore this', 'bufnr': g:buffer},
|
||||||
|
\ {'lnum': 20, 'col': 5, 'text': 'baz', 'bufnr': g:new_buffer},
|
||||||
|
\ {'lnum': 10, 'col': 6, 'text': 'bar', 'bufnr': g:new_buffer},
|
||||||
|
\ {'lnum': 10, 'col': 5, 'text': 'foo', 'bufnr': g:new_buffer},
|
||||||
|
\])
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ {'lnum': 10, 'col': 5, 'text': 'foo'},
|
||||||
|
\ {'lnum': 10, 'col': 6, 'text': 'bar'},
|
||||||
|
\ {'lnum': 20, 'col': 5, 'text': 'baz'},
|
||||||
|
\ ],
|
||||||
|
\ GetList()
|
||||||
|
|
||||||
|
Execute(An empty List should be returned when both lists are turned off):
|
||||||
|
let g:ale_set_loclist = 0
|
||||||
|
let g:ale_set_quickfix = 0
|
||||||
|
|
||||||
|
call setqflist([{'lnum': 1, 'col': 1, 'text': 'foo', 'bufnr': bufnr('%')}])
|
||||||
|
call setloclist(winnr(), [{'lnum': 1, 'col': 1, 'text': 'foo', 'bufnr': bufnr('%')}])
|
||||||
|
|
||||||
|
AssertEqual [], GetList()
|
Loading…
Reference in New Issue
Block a user