diff options
author | Andrey Popp <8mayday@gmail.com> | 2019-01-22 02:06:28 +0300 |
---|---|---|
committer | w0rp <w0rp@users.noreply.github.com> | 2019-01-21 23:06:28 +0000 |
commit | d0284f22ea45a5e7796da2224373c22232af1777 (patch) | |
tree | cdb86bbb13a5d0c11f6579aeebe4deaed75e32ab /autoload | |
parent | a4932679b5c0d2917a399614a25c9827d63eecb1 (diff) | |
download | ale-d0284f22ea45a5e7796da2224373c22232af1777.zip |
Add textDocument/typeDefinition for LSP (#2226)
* Add textDocument/typeDefinition for LSP
Doc to spec https://microsoft.github.io/language-server-protocol/specification#textDocument_typeDefinition
This works like textDocument/definition but resolves a location of a
type of an expression under the cursor.
I'm not sure what to do with tsserver though.
* Fix passing column to LSP
* test_go_to_definition: wording
* Add tests for textDocument/typeDefinition
* Add docs for textDocument/typeDefinition
Diffstat (limited to 'autoload')
-rw-r--r-- | autoload/ale/definition.vim | 33 | ||||
-rw-r--r-- | autoload/ale/lsp.vim | 5 | ||||
-rw-r--r-- | autoload/ale/lsp/message.vim | 9 |
3 files changed, 41 insertions, 6 deletions
diff --git a/autoload/ale/definition.vim b/autoload/ale/definition.vim index 79d12596..a732e501 100644 --- a/autoload/ale/definition.vim +++ b/autoload/ale/definition.vim @@ -57,7 +57,7 @@ function! ale#definition#HandleLSPResponse(conn_id, response) abort endif endfunction -function! s:OnReady(linter, lsp_details, line, column, options, ...) abort +function! s:OnReady(linter, lsp_details, line, column, options, capability, ...) abort let l:buffer = a:lsp_details.buffer let l:id = a:lsp_details.connection_id @@ -80,7 +80,14 @@ function! s:OnReady(linter, lsp_details, line, column, options, ...) abort " For LSP completions, we need to clamp the column to the length of " the line. python-language-server and perhaps others do not implement " this correctly. - let l:message = ale#lsp#message#Definition(l:buffer, a:line, a:column) + if a:capability is# 'definition' + let l:message = ale#lsp#message#Definition(l:buffer, a:line, a:column) + elseif a:capability is# 'typeDefinition' + let l:message = ale#lsp#message#TypeDefinition(l:buffer, a:line, a:column) + else + " XXX: log here? + return + endif endif let l:request_id = ale#lsp#Send(l:id, l:message) @@ -90,7 +97,7 @@ function! s:OnReady(linter, lsp_details, line, column, options, ...) abort \} endfunction -function! s:GoToLSPDefinition(linter, options) abort +function! s:GoToLSPDefinition(linter, options, capability) abort let l:buffer = bufnr('') let [l:line, l:column] = getcurpos()[1:2] let l:lsp_details = ale#lsp_linter#StartLSP(l:buffer, a:linter) @@ -105,15 +112,29 @@ function! s:GoToLSPDefinition(linter, options) abort let l:id = l:lsp_details.connection_id - call ale#lsp#WaitForCapability(l:id, 'definition', function('s:OnReady', [ - \ a:linter, l:lsp_details, l:line, l:column, a:options + call ale#lsp#WaitForCapability(l:id, a:capability, function('s:OnReady', [ + \ a:linter, l:lsp_details, l:line, l:column, a:options, a:capability \])) endfunction function! ale#definition#GoTo(options) abort for l:linter in ale#linter#Get(&filetype) if !empty(l:linter.lsp) - call s:GoToLSPDefinition(l:linter, a:options) + call s:GoToLSPDefinition(l:linter, a:options, 'definition') + endif + endfor +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 endfunction diff --git a/autoload/ale/lsp.vim b/autoload/ale/lsp.vim index f55096c2..95ab83cf 100644 --- a/autoload/ale/lsp.vim +++ b/autoload/ale/lsp.vim @@ -43,6 +43,7 @@ function! ale#lsp#Register(executable_or_address, project, init_options) abort \ 'completion': 0, \ 'completion_trigger_characters': [], \ 'definition': 0, + \ 'typeDefinition': 0, \ 'symbol_search': 0, \ }, \} @@ -207,6 +208,10 @@ function! s:UpdateCapabilities(conn, capabilities) abort let a:conn.capabilities.definition = 1 endif + if get(a:capabilities, 'typeDefinitionProvider') is v:true + let a:conn.capabilities.typeDefinition = 1 + endif + if get(a:capabilities, 'workspaceSymbolProvider') is v:true let a:conn.capabilities.symbol_search = 1 endif diff --git a/autoload/ale/lsp/message.vim b/autoload/ale/lsp/message.vim index a9921478..cc0b2227 100644 --- a/autoload/ale/lsp/message.vim +++ b/autoload/ale/lsp/message.vim @@ -124,6 +124,15 @@ function! ale#lsp#message#Definition(buffer, line, column) abort \}] endfunction +function! ale#lsp#message#TypeDefinition(buffer, line, column) abort + return [0, 'textDocument/typeDefinition', { + \ 'textDocument': { + \ 'uri': ale#path#ToURI(expand('#' . a:buffer . ':p')), + \ }, + \ 'position': {'line': a:line - 1, 'character': a:column - 1}, + \}] +endfunction + function! ale#lsp#message#References(buffer, line, column) abort return [0, 'textDocument/references', { \ 'textDocument': { |