#653 - Jump to the position which Vim does not jump to for moving from quickfix/loclist items to other buffers
This commit is contained in:
parent
47e681529b
commit
456378cb53
@ -60,10 +60,40 @@ function! s:HitReturn(...) abort
|
|||||||
|
|
||||||
if get(split(l:output, "\n"), -1, '') =~# '^E92[456]'
|
if get(split(l:output, "\n"), -1, '') =~# '^E92[456]'
|
||||||
call ale#util#FeedKeys("\<CR>", 'n')
|
call ale#util#FeedKeys("\<CR>", 'n')
|
||||||
|
|
||||||
|
" If we hit one of the errors and cleared it, then Vim didn't
|
||||||
|
" move to the position we wanted. Change the position to the one
|
||||||
|
" the user selected.
|
||||||
|
if exists('g:ale_list_window_selection')
|
||||||
|
let l:pos = getcurpos()
|
||||||
|
let [l:pos[1], l:pos[2]] = g:ale_list_window_selection
|
||||||
|
call setpos('.', l:pos)
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
" Always clear the last selection when trying to cancel the errors above
|
||||||
|
" here. This prevents us from remembering invalid positions.
|
||||||
|
unlet! g:ale_list_window_selection
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! ale#events#BufWinLeave() abort
|
function! ale#events#BufWinLeave() abort
|
||||||
call timer_start(0, function('s:HitReturn'))
|
call timer_start(0, function('s:HitReturn'))
|
||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
|
" Grab the position for a problem from the loclist or quickfix windows
|
||||||
|
" when moving through selections. This selection will be remembered and
|
||||||
|
" set as the position when jumping to an error in another file.
|
||||||
|
function! ale#events#ParseLoclistWindowItemPosition() abort
|
||||||
|
" Parses lines like
|
||||||
|
" test.txt|72 col 5 error| ...
|
||||||
|
" test.txt|72| ...
|
||||||
|
let l:match = matchlist(getline('.'), '\v^[^|]+\|(\d+)( [^ ]+ )?(\d*)')
|
||||||
|
|
||||||
|
if !empty(l:match)
|
||||||
|
let g:ale_list_window_selection = [
|
||||||
|
\ l:match[1] + 0,
|
||||||
|
\ max([l:match[3] + 0, 1]),
|
||||||
|
\]
|
||||||
|
endif
|
||||||
|
endfunction
|
||||||
|
4
ftplugin/qf.vim
Normal file
4
ftplugin/qf.vim
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
augroup ALEQuickfixCursorMovedEvent
|
||||||
|
autocmd! * <buffer>
|
||||||
|
autocmd CursorMoved <buffer> call ale#events#ParseLoclistWindowItemPosition()
|
||||||
|
augroup END
|
@ -21,8 +21,14 @@ Before:
|
|||||||
let l:header = split(l:line)[1]
|
let l:header = split(l:line)[1]
|
||||||
let l:header = get(l:event_name_corrections, l:header, l:header)
|
let l:header = get(l:event_name_corrections, l:header, l:header)
|
||||||
elseif !empty(l:header)
|
elseif !empty(l:header)
|
||||||
call add(l:matches, join(split(l:header . l:line)))
|
" There's an extra line for buffer events, and we should only look
|
||||||
let l:header = ''
|
" for the one matching the current buffer.
|
||||||
|
if l:line =~# '<buffer=' . bufnr('') . '>'
|
||||||
|
let l:header .= ' <buffer>'
|
||||||
|
else
|
||||||
|
call add(l:matches, join(split(l:header . l:line)))
|
||||||
|
let l:header = ''
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endfor
|
endfor
|
||||||
|
|
||||||
@ -54,6 +60,11 @@ After:
|
|||||||
|
|
||||||
call ALEInitAuGroups()
|
call ALEInitAuGroups()
|
||||||
|
|
||||||
|
" Clean up the quickfix group.
|
||||||
|
augroup ALEQuickfixCursorMovedEvent
|
||||||
|
autocmd! * <buffer>
|
||||||
|
augroup END
|
||||||
|
|
||||||
Execute (g:ale_lint_on_text_changed = 0 should bind no events):
|
Execute (g:ale_lint_on_text_changed = 0 should bind no events):
|
||||||
let g:ale_lint_on_text_changed = 0
|
let g:ale_lint_on_text_changed = 0
|
||||||
|
|
||||||
@ -211,3 +222,12 @@ Execute(Disabling completion should remove autocmd events correctly):
|
|||||||
|
|
||||||
AssertEqual [], CheckAutocmd('ALECompletionGroup')
|
AssertEqual [], CheckAutocmd('ALECompletionGroup')
|
||||||
AssertEqual 0, g:ale_completion_enabled
|
AssertEqual 0, g:ale_completion_enabled
|
||||||
|
|
||||||
|
Execute(The cursor events should be set up for the quickfix list):
|
||||||
|
runtime! ftplugin/qf.vim
|
||||||
|
|
||||||
|
AssertEqual
|
||||||
|
\ [
|
||||||
|
\ 'CursorMoved <buffer> call ale#events#ParseLoclistWindowItemPosition()',
|
||||||
|
\ ],
|
||||||
|
\ CheckAutocmd('ALEQuickfixCursorMovedEvent')
|
||||||
|
@ -26,6 +26,7 @@ Before:
|
|||||||
After:
|
After:
|
||||||
unlet! b:fake_mode
|
unlet! b:fake_mode
|
||||||
unlet! b:feedkeys_calls
|
unlet! b:feedkeys_calls
|
||||||
|
unlet! g:ale_list_window_selection
|
||||||
|
|
||||||
delfunction CheckError
|
delfunction CheckError
|
||||||
|
|
||||||
@ -52,3 +53,44 @@ Execute(The BufWinLeave event function should ignore other errors):
|
|||||||
|
|
||||||
Execute(The BufWinLeave event function not send keys for other modes):
|
Execute(The BufWinLeave event function not send keys for other modes):
|
||||||
call CheckError('n', 'E924', [])
|
call CheckError('n', 'E924', [])
|
||||||
|
|
||||||
|
Execute(The last window selection should always be cleared by the timer):
|
||||||
|
let g:ale_list_window_selection = [347, 2]
|
||||||
|
|
||||||
|
" The message and mode shouldn't matter, we should still clear the variable.
|
||||||
|
echom 'xyz'
|
||||||
|
let b:fake_mode = 'n'
|
||||||
|
call ale#events#BufWinLeave()
|
||||||
|
sleep 1ms
|
||||||
|
|
||||||
|
Assert !has_key(g:, 'ale_list_window_selection')
|
||||||
|
|
||||||
|
Given qf(A quickfix list with some errors):
|
||||||
|
test.txt|23 col 9 warning| Some warning
|
||||||
|
test.txt|72 col 25 error| Some column error
|
||||||
|
test.txt|93 error| Some line error
|
||||||
|
|
||||||
|
Execute(Line and column numbers should be parsed by the quickfix event function):
|
||||||
|
call setpos('.', [bufnr(''), 2, 1, 0])
|
||||||
|
call ale#events#ParseLoclistWindowItemPosition()
|
||||||
|
AssertEqual [72, 25], g:ale_list_window_selection
|
||||||
|
|
||||||
|
Execute(Just Line numbers should be parsed by the quickfix event function):
|
||||||
|
call setpos('.', [bufnr(''), 3, 1, 0])
|
||||||
|
call ale#events#ParseLoclistWindowItemPosition()
|
||||||
|
AssertEqual [93, 1], g:ale_list_window_selection
|
||||||
|
|
||||||
|
Given python(Some example Python file):
|
||||||
|
class FooBar:
|
||||||
|
def whatever(self):
|
||||||
|
self.do_something()
|
||||||
|
|
||||||
|
Execute(We should jump to the window selection after cancelling the errors):
|
||||||
|
call setpos('.', [bufnr(''), 1, 1, 0])
|
||||||
|
let g:ale_list_window_selection = [3, 9]
|
||||||
|
|
||||||
|
echom 'E925'
|
||||||
|
call ale#events#BufWinLeave()
|
||||||
|
sleep 1ms
|
||||||
|
|
||||||
|
AssertEqual [3, 9], getcurpos()[1:2]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user