Skip to content

Instantly share code, notes, and snippets.

@presuku
Last active November 15, 2019 04:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save presuku/9d3aecf0be0d2a0c0ccc6ef11fa6b0b6 to your computer and use it in GitHub Desktop.
Save presuku/9d3aecf0be0d2a0c0ccc6ef11fa6b0b6 to your computer and use it in GitHub Desktop.
tagstack and LspDefinition
function! s:lsp_def_add_stack() abort
let l:tagname = expand('<cword>')
let l:tagstack = gettagstack()
let l:bufnr = bufnr('%')
let l:pos = getpos('.')
execute("LspDefinition")
if l:tagstack.curidx == 1
let l:action = 'r'
let l:length = 1
let l:curidx = l:tagstack.curidx + 1
else
let l:action = 'a'
let l:length = l:tagstack.length + 1
let l:curidx = l:tagstack.curidx + 1
endif
let l:pos[0] = l:bufnr
let l:newtag = [{'tagname': l:tagname, 'from': l:pos, 'bufnr': bufnr("%")}]
call settagstack(win_getid(),
\ {'length': l:length, 'curidx': l:curidx, 'items': l:newtag},
\ l:action)
endfunction
command! LspDef call s:lsp_def_add_stack()
nnoremap <C-]> :<C-u>call <SID>lsp_def_add_stack()<CR>
@presuku
Copy link
Author

presuku commented Nov 15, 2019

this code is too old and a bit wrong.
And now, vim-lsp support tagstack correctlry at prabirshrestha/vim-lsp/pull/449.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment