Merge pull request #2448 from reedriley/master

Add support for Vim's tagstack to ALEGoToDefinition
This commit is contained in:
w0rp 2019-04-29 20:55:45 +01:00 committed by GitHub
commit 2f3bce5a1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 40 additions and 1 deletions

View File

@ -1,7 +1,7 @@
FROM tweekmonster/vim-testbed:latest FROM tweekmonster/vim-testbed:latest
RUN install_vim -tag v8.0.0027 -build \ RUN install_vim -tag v8.0.0027 -build \
-tag v8.1.0204 -build \ -tag v8.1.0519 -build \
-tag neovim:v0.2.0 -build \ -tag neovim:v0.2.0 -build \
-tag neovim:v0.3.0 -build -tag neovim:v0.3.0 -build

View File

@ -3,6 +3,9 @@
let s:go_to_definition_map = {} let s:go_to_definition_map = {}
" Enable automatic updates of the tagstack
let g:ale_update_tagstack = get(g:, 'ale_update_tagstack', 1)
" Used to get the definition map in tests. " Used to get the definition map in tests.
function! ale#definition#GetMap() abort function! ale#definition#GetMap() abort
return deepcopy(s:go_to_definition_map) return deepcopy(s:go_to_definition_map)
@ -17,6 +20,20 @@ function! ale#definition#ClearLSPData() abort
let s:go_to_definition_map = {} let s:go_to_definition_map = {}
endfunction endfunction
function! ale#definition#UpdateTagStack() abort
let l:should_update_tagstack = exists('*gettagstack') && exists('*settagstack') && g:ale_update_tagstack
if l:should_update_tagstack
" Grab the old location (to jump back to) and the word under the
" cursor (as a label for the tagstack)
let l:old_location = [bufnr('%'), line('.'), col('.'), 0]
let l:tagname = expand('<cword>')
let l:winid = win_getid()
call settagstack(l:winid, {'items': [{'from': l:old_location, 'tagname': l:tagname}]}, 'a')
call settagstack(l:winid, {'curidx': len(gettagstack(l:winid)['items']) + 1})
endif
endfunction
function! ale#definition#HandleTSServerResponse(conn_id, response) abort function! ale#definition#HandleTSServerResponse(conn_id, response) abort
if get(a:response, 'command', '') is# 'definition' if get(a:response, 'command', '') is# 'definition'
\&& has_key(s:go_to_definition_map, a:response.request_seq) \&& has_key(s:go_to_definition_map, a:response.request_seq)
@ -27,6 +44,7 @@ function! ale#definition#HandleTSServerResponse(conn_id, response) abort
let l:line = a:response.body[0].start.line let l:line = a:response.body[0].start.line
let l:column = a:response.body[0].start.offset let l:column = a:response.body[0].start.offset
call ale#definition#UpdateTagStack()
call ale#util#Open(l:filename, l:line, l:column, l:options) call ale#util#Open(l:filename, l:line, l:column, l:options)
endif endif
endif endif
@ -51,6 +69,7 @@ function! ale#definition#HandleLSPResponse(conn_id, response) abort
let l:line = l:item.range.start.line + 1 let l:line = l:item.range.start.line + 1
let l:column = l:item.range.start.character + 1 let l:column = l:item.range.start.character + 1
call ale#definition#UpdateTagStack()
call ale#util#Open(l:filename, l:line, l:column, l:options) call ale#util#Open(l:filename, l:line, l:column, l:options)
break break
endfor endfor

View File

@ -375,6 +375,9 @@ information returned by LSP servers. The following commands are supported:
|ALEGoToDefinitionInSplit| - The same, but in a new split. |ALEGoToDefinitionInSplit| - The same, but in a new split.
|ALEGoToDefinitionInVSplit| - The same, but in a new vertical split. |ALEGoToDefinitionInVSplit| - The same, but in a new vertical split.
ALE will update Vim's |tagstack| automatically unless |g:ale_update_tagstack| is
set to `0`.
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
5.3 Go To Type Definition *ale-go-to-type-definition* 5.3 Go To Type Definition *ale-go-to-type-definition*
@ -1498,6 +1501,14 @@ g:ale_sign_warning *g:ale_sign_warning*
The sign for warnings in the sign gutter. The sign for warnings in the sign gutter.
g:ale_update_tagstack *g:ale_update_tagstack*
*b:ale_update_tagstack*
Type: |Number|
Default: `1`
This option can be set to disable updating Vim's |tagstack| automatically.
g:ale_type_map *g:ale_type_map* g:ale_type_map *g:ale_type_map*
*b:ale_type_map* *b:ale_type_map*
Type: |Dictionary| Type: |Dictionary|

View File

@ -78,6 +78,15 @@ After:
Execute(Other messages for the tsserver handler should be ignored): Execute(Other messages for the tsserver handler should be ignored):
call ale#definition#HandleTSServerResponse(1, {'command': 'foo'}) call ale#definition#HandleTSServerResponse(1, {'command': 'foo'})
Execute(Tagstack should be incremented if supported):
if exists('*gettagstack') && exists('*settagstack')
let original_stack_depth = gettagstack().length
endif
call ale#definition#UpdateTagStack()
if exists('*gettagstack') && exists('*settagstack')
AssertEqual original_stack_depth + 1, gettagstack().length
endif
Execute(Failed definition responses should be handled correctly): Execute(Failed definition responses should be handled correctly):
call ale#definition#SetMap({3: {'open_in': 'current-buffer'}}) call ale#definition#SetMap({3: {'open_in': 'current-buffer'}})
call ale#definition#HandleTSServerResponse( call ale#definition#HandleTSServerResponse(