Skip to content

Commit 1366e07

Browse files
added :LspTypeDefinition (#165)
1 parent f9c32e3 commit 1366e07

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Refer to docs on configuring omnifunc or [asyncomplete.vim](https://github.com/p
6262
|`:LspImplementation` | Show implementation of interface |
6363
|`:LspReferences`| Find references |
6464
|`:LspRename`| Rename symbol |
65+
|`:LspTypeDefinition`| Go to type definition |
6566
|`:LspWorkspaceSymbol`| Search/Show workspace symbol |
6667

6768
### Diagnostics

autoload/lsp/capabilities.vim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ function! lsp#capabilities#has_implementation_provider(server_name) abort
3939
return s:has_bool_provider(a:server_name, 'implementationProvider')
4040
endfunction
4141

42+
function! lsp#capabilities#has_type_definition_provider(server_name) abort
43+
return s:has_bool_provider(a:server_name, 'typeDefinitionProvider')
44+
endfunction
45+
4246
" [supports_did_save (boolean), { 'includeText': boolean }]
4347
function! lsp#capabilities#get_text_document_save_registration_options(server_name) abort
4448
let l:capabilities = lsp#get_server_capabilities(a:server_name)

autoload/lsp/ui/vim.vim

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,30 @@ function! lsp#ui#vim#implementation() abort
2828
echo 'Retrieving implementation ...'
2929
endfunction
3030

31+
function! lsp#ui#vim#type_definition() abort
32+
let l:servers = filter(lsp#get_whitelisted_servers(), 'lsp#capabilities#has_type_definition_provider(v:val)')
33+
let s:last_req_id = s:last_req_id + 1
34+
call setqflist([])
35+
36+
if len(l:servers) == 0
37+
call s:not_supported('Retrieving type definition')
38+
return
39+
endif
40+
let l:ctx = { 'counter': len(l:servers), 'list':[], 'last_req_id': s:last_req_id, 'jump_if_one': 1 }
41+
for l:server in l:servers
42+
call lsp#send_request(l:server, {
43+
\ 'method': 'textDocument/typeDefinition',
44+
\ 'params': {
45+
\ 'textDocument': lsp#get_text_document_identifier(),
46+
\ 'position': lsp#get_position(),
47+
\ },
48+
\ 'on_notification': function('s:handle_location', [l:ctx, l:server, 'type definition']),
49+
\ })
50+
endfor
51+
52+
echo 'Retrieving type definition ...'
53+
endfunction
54+
3155
function! lsp#ui#vim#definition() abort
3256
let l:servers = filter(lsp#get_whitelisted_servers(), 'lsp#capabilities#has_definition_provider(v:val)')
3357
let s:last_req_id = s:last_req_id + 1

doc/vim-lsp.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ CONTENTS *vim-lsp-contents*
2929
LspImplementation |LspImplementation|
3030
LspReferences |LspReferences|
3131
LspRename |LspRename|
32+
LspTypeDefinition |LspTypeDefinition|
3233
LspWorkspaceSymbols |LspWorkspaceSymbols|
3334
Autocomplete |vim-lsp-autocomplete|
3435
omnifunc |vim-lsp-omnifunc|
@@ -313,7 +314,7 @@ Gets the hover information and displays it in the |preview-window|.
313314
configure |g:lsp_preview_keep_focus|.
314315

315316

316-
LspNextError *LspNextError*
317+
LspNextError *LspNextError*
317318

318319
Jump to Next err diagnostics
319320

@@ -333,11 +334,15 @@ LspRename *LspRename*
333334

334335
Rename the symbol.
335336

337+
LspTypeDefinition *LspTypeDefinition*
338+
339+
Go to the type definition.
340+
336341
LspWorkspaceSymbols *LspWorkspaceSymbols*
337342

338343
Search and show workspace symbols.
339344

340-
LspStatus *LspStatus*
345+
LspStatus *LspStatus*
341346

342347
Prints the status of all registered servers.
343348

plugin/lsp.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,5 @@ command! LspWorkspaceSymbol call lsp#ui#vim#workspace_symbol()
3434
command! LspDocumentFormat call lsp#ui#vim#document_format()
3535
command! -range LspDocumentRangeFormat call lsp#ui#vim#document_range_format()
3636
command! LspImplementation call lsp#ui#vim#implementation()
37+
command! LspTypeDefinition call lsp#ui#vim#type_definition()
3738
command! -nargs=0 LspStatus echo lsp#get_server_status()

0 commit comments

Comments
 (0)