Support going to type definition with tsserver (#3545)

This commit is contained in:
Alex LaFroscia
2021-02-20 11:09:28 -05:00
committed by GitHub
parent 3ea887d2f4
commit d340710fcf
5 changed files with 60 additions and 12 deletions

View File

@@ -36,7 +36,7 @@ function! ale#definition#UpdateTagStack() abort
endfunction
function! ale#definition#HandleTSServerResponse(conn_id, response) abort
if get(a:response, 'command', '') is# 'definition'
if has_key(a:response, 'request_seq')
\&& has_key(s:go_to_definition_map, a:response.request_seq)
let l:options = remove(s:go_to_definition_map, a:response.request_seq)
@@ -92,11 +92,19 @@ function! s:OnReady(line, column, options, capability, linter, lsp_details) abor
call ale#lsp#RegisterCallback(l:id, l:Callback)
if a:linter.lsp is# 'tsserver'
let l:message = ale#lsp#tsserver_message#Definition(
\ l:buffer,
\ a:line,
\ a:column
\)
if a:capability is# 'definition'
let l:message = ale#lsp#tsserver_message#Definition(
\ l:buffer,
\ a:line,
\ a:column
\)
elseif a:capability is# 'typeDefinition'
let l:message = ale#lsp#tsserver_message#TypeDefinition(
\ l:buffer,
\ a:line,
\ a:column
\)
endif
else
" Send a message saying the buffer has changed first, or the
" definition position probably won't make sense.
@@ -145,12 +153,6 @@ endfunction
function! ale#definition#GoToType(options) abort
for l:linter in ale#linter#Get(&filetype)
if !empty(l:linter.lsp)
" TODO: handle typeDefinition for tsserver if supported by the
" protocol
if l:linter.lsp is# 'tsserver'
continue
endif
call s:GoToLSPDefinition(l:linter, a:options, 'typeDefinition')
endif
endfor

View File

@@ -357,6 +357,7 @@ function! ale#lsp#MarkConnectionAsTsserver(conn_id) abort
let l:conn.capabilities.completion = 1
let l:conn.capabilities.completion_trigger_characters = ['.']
let l:conn.capabilities.definition = 1
let l:conn.capabilities.typeDefinition = 1
let l:conn.capabilities.symbol_search = 1
let l:conn.capabilities.rename = 1
let l:conn.capabilities.code_actions = 1

View File

@@ -64,6 +64,14 @@ function! ale#lsp#tsserver_message#Definition(buffer, line, column) abort
\}]
endfunction
function! ale#lsp#tsserver_message#TypeDefinition(buffer, line, column) abort
return [0, 'ts@typeDefinition', {
\ 'line': a:line,
\ 'offset': a:column,
\ 'file': expand('#' . a:buffer . ':p'),
\}]
endfunction
function! ale#lsp#tsserver_message#References(buffer, line, column) abort
return [0, 'ts@references', {
\ 'line': a:line,