June 12, 2020

Vim typescript jump-to-definition

  1. Use vim 8.1 or newer (in older version of vim, tagstack doesn’t work with the solution below)
  2. Install ALE https://github.com/dense-analysis/ale
  3. bind Ctrl-] to ALEGoToDefinition using the following snippet of code
function ALELSPMappings()
    let l:lsp_found=0
    for l:linter in ale#linter#Get(&filetype) | if !empty(l:linter.lsp) | let l:lsp_found=1 | endif | endfor
    if (l:lsp_found)
        nnoremap <buffer> <C-]> :ALEGoToDefinition<CR>
        nnoremap <buffer> <C-^> :ALEFindReferences<CR>
    else
        silent! unmap <buffer> <C-]>
        silent! unmap <buffer> <C-^>
    endif
endfunction
autocmd BufRead,FileType * call ALELSPMappings()
  1. install tsserver if you have not done so using npm
  2. Done.

No comments:

Post a Comment