Add :ALEFirst and :ALELast commands (#616)
* Add :ALEFirst and :ALELast commands * Add documentation for ALEFirst and ALELast commands * Add tests for ale#loclist_jumping#JumpToIndex() * Fix the loclist jumping tests
This commit is contained in:
parent
fcb5718712
commit
33b0852c84
@ -64,3 +64,16 @@ function! ale#loclist_jumping#Jump(direction, wrap) abort
|
|||||||
call cursor(l:nearest)
|
call cursor(l:nearest)
|
||||||
endif
|
endif
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
function! ale#loclist_jumping#JumpToIndex(index) abort
|
||||||
|
let l:info = get(g:ale_buffer_info, bufnr('%'), {'loclist': []})
|
||||||
|
let l:loclist = l:info.loclist
|
||||||
|
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
|
||||||
|
endfunction
|
||||||
|
@ -857,6 +857,8 @@ ALEPrevious *ALEPrevious*
|
|||||||
ALEPreviousWrap *ALEPreviousWrap*
|
ALEPreviousWrap *ALEPreviousWrap*
|
||||||
ALENext *ALENext*
|
ALENext *ALENext*
|
||||||
ALENextWrap *ALENextWrap*
|
ALENextWrap *ALENextWrap*
|
||||||
|
ALEFirst *ALEFirst*
|
||||||
|
ALELast *ALELast*
|
||||||
*ale-navigation-commands*
|
*ale-navigation-commands*
|
||||||
|
|
||||||
Move between warnings or errors in a buffer. ALE will only navigate between
|
Move between warnings or errors in a buffer. ALE will only navigate between
|
||||||
@ -867,11 +869,16 @@ ALENextWrap *ALENextWrap*
|
|||||||
`ALEPreviousWrap` and `ALENextWrap` will wrap around the file to find
|
`ALEPreviousWrap` and `ALENextWrap` will wrap around the file to find
|
||||||
the last or first warning or error in the file, respectively.
|
the last or first warning or error in the file, respectively.
|
||||||
|
|
||||||
|
`ALEFirst` goes the the first error or warning in the buffer, while `ALELast`
|
||||||
|
goes to the last one.
|
||||||
|
|
||||||
The following |<Plug>| mappings are defined for the commands: >
|
The following |<Plug>| mappings are defined for the commands: >
|
||||||
<Plug>(ale_previous) - ALEPrevious
|
<Plug>(ale_previous) - ALEPrevious
|
||||||
<Plug>(ale_previous_wrap) - ALEPreviousWrap
|
<Plug>(ale_previous_wrap) - ALEPreviousWrap
|
||||||
<Plug>(ale_next) - ALENext
|
<Plug>(ale_next) - ALENext
|
||||||
<Plug>(ale_next_wrap) - ALENextWrap
|
<Plug>(ale_next_wrap) - ALENextWrap
|
||||||
|
<Plug>(ale_first) - ALEFirst
|
||||||
|
<Plug>(ale_last) - ALELast
|
||||||
<
|
<
|
||||||
For example, these commands could be bound to the keys Ctrl + j
|
For example, these commands could be bound to the keys Ctrl + j
|
||||||
and Ctrl + k: >
|
and Ctrl + k: >
|
||||||
|
@ -311,6 +311,8 @@ command! -bar ALEPrevious :call ale#loclist_jumping#Jump('before', 0)
|
|||||||
command! -bar ALEPreviousWrap :call ale#loclist_jumping#Jump('before', 1)
|
command! -bar ALEPreviousWrap :call ale#loclist_jumping#Jump('before', 1)
|
||||||
command! -bar ALENext :call ale#loclist_jumping#Jump('after', 0)
|
command! -bar ALENext :call ale#loclist_jumping#Jump('after', 0)
|
||||||
command! -bar ALENextWrap :call ale#loclist_jumping#Jump('after', 1)
|
command! -bar ALENextWrap :call ale#loclist_jumping#Jump('after', 1)
|
||||||
|
command! -bar ALEFirst :call ale#loclist_jumping#JumpToIndex(0)
|
||||||
|
command! -bar ALELast :call ale#loclist_jumping#JumpToIndex(-1)
|
||||||
|
|
||||||
" A command for showing error details.
|
" A command for showing error details.
|
||||||
command! -bar ALEDetail :call ale#cursor#ShowCursorDetail()
|
command! -bar ALEDetail :call ale#cursor#ShowCursorDetail()
|
||||||
@ -338,6 +340,8 @@ nnoremap <silent> <Plug>(ale_previous) :ALEPrevious<Return>
|
|||||||
nnoremap <silent> <Plug>(ale_previous_wrap) :ALEPreviousWrap<Return>
|
nnoremap <silent> <Plug>(ale_previous_wrap) :ALEPreviousWrap<Return>
|
||||||
nnoremap <silent> <Plug>(ale_next) :ALENext<Return>
|
nnoremap <silent> <Plug>(ale_next) :ALENext<Return>
|
||||||
nnoremap <silent> <Plug>(ale_next_wrap) :ALENextWrap<Return>
|
nnoremap <silent> <Plug>(ale_next_wrap) :ALENextWrap<Return>
|
||||||
|
nnoremap <silent> <Plug>(ale_first) :ALEFirst<Return>
|
||||||
|
nnoremap <silent> <Plug>(ale_last) :ALELast<Return>
|
||||||
nnoremap <silent> <Plug>(ale_toggle) :ALEToggle<Return>
|
nnoremap <silent> <Plug>(ale_toggle) :ALEToggle<Return>
|
||||||
nnoremap <silent> <Plug>(ale_lint) :ALELint<Return>
|
nnoremap <silent> <Plug>(ale_lint) :ALELint<Return>
|
||||||
nnoremap <silent> <Plug>(ale_detail) :ALEDetail<Return>
|
nnoremap <silent> <Plug>(ale_detail) :ALEDetail<Return>
|
||||||
|
@ -13,9 +13,14 @@ Before:
|
|||||||
\ },
|
\ },
|
||||||
\}
|
\}
|
||||||
|
|
||||||
function! TestJump(direction, wrap, pos)
|
function! TestJump(position, wrap, pos)
|
||||||
call cursor(a:pos)
|
call cursor(a:pos)
|
||||||
call ale#loclist_jumping#Jump(a:direction, a:wrap)
|
|
||||||
|
if type(a:position) == type(0)
|
||||||
|
call ale#loclist_jumping#JumpToIndex(a:position)
|
||||||
|
else
|
||||||
|
call ale#loclist_jumping#Jump(a:position, a:wrap)
|
||||||
|
endif
|
||||||
|
|
||||||
return getcurpos()[1:2]
|
return getcurpos()[1:2]
|
||||||
endfunction
|
endfunction
|
||||||
@ -53,3 +58,19 @@ Execute(loclist jumping not jump when the loclist is empty):
|
|||||||
AssertEqual [1, 6], TestJump('before', 1, [1, 6])
|
AssertEqual [1, 6], TestJump('before', 1, [1, 6])
|
||||||
AssertEqual [1, 6], TestJump('after', 0, [1, 6])
|
AssertEqual [1, 6], TestJump('after', 0, [1, 6])
|
||||||
AssertEqual [1, 6], TestJump('after', 1, [1, 6])
|
AssertEqual [1, 6], TestJump('after', 1, [1, 6])
|
||||||
|
|
||||||
|
Execute(We should be able to jump to the last item):
|
||||||
|
AssertEqual [2, 8], TestJump(-1, 0, [1, 6])
|
||||||
|
|
||||||
|
Execute(We shouldn't move when jumping to the last item where there are none):
|
||||||
|
let g:ale_buffer_info[bufnr('%')].loclist = []
|
||||||
|
|
||||||
|
AssertEqual [1, 6], TestJump(-1, 0, [1, 6])
|
||||||
|
|
||||||
|
Execute(We should be able to jump to the first item):
|
||||||
|
AssertEqual [1, 2], TestJump(0, 0, [1, 6])
|
||||||
|
|
||||||
|
Execute(We shouldn't move when jumping to the first item where there are none):
|
||||||
|
let g:ale_buffer_info[bufnr('%')].loclist = []
|
||||||
|
|
||||||
|
AssertEqual [1, 6], TestJump(0, 0, [1, 6])
|
Loading…
Reference in New Issue
Block a user