-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Vim's tagstack to ALEGoToDefinition #2448
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,9 @@ | |
|
||
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. | ||
function! ale#definition#GetMap() abort | ||
return deepcopy(s:go_to_definition_map) | ||
|
@@ -17,6 +20,20 @@ function! ale#definition#ClearLSPData() abort | |
let s:go_to_definition_map = {} | ||
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Get the window ID from the buffer number, instead of the current window. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This sounds like it's probably really relevant and important - but I'm afraid I'm not an expert on the Vim functions involving windows and buffers. Any chance you can provide some pointers to the relevant docs? |
||
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 | ||
if get(a:response, 'command', '') is# 'definition' | ||
\&& 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:column = a:response.body[0].start.offset | ||
|
||
call ale#definition#UpdateTagStack() | ||
call ale#util#Open(l:filename, l:line, l:column, l:options) | ||
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:column = l:item.range.start.character + 1 | ||
|
||
call ale#definition#UpdateTagStack() | ||
call ale#util#Open(l:filename, l:line, l:column, l:options) | ||
break | ||
endfor | ||
|
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above - the values I'm pushing on to the stack are based on the old location. So I don't think I need to wait for the buffer to open; assuming I've understood this comment correctly?