diff options
author | Ole Krüger | 2023-01-31 10:38:53 +0000 |
---|---|---|
committer | GitHub | 2023-01-31 10:38:53 +0000 |
commit | 4eca4b3079bf53de874959270d0b3471d320debc (patch) | |
tree | 685da9a2ef16df7b0c135a636f2324e5a2248802 /helix-term/src/commands | |
parent | c9b583ea9b59aa78c12e3831ed9c73f83d1d35d8 (diff) |
Support goto-declaration LSP command (#5646)
Diffstat (limited to 'helix-term/src/commands')
-rw-r--r-- | helix-term/src/commands/lsp.rs | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/helix-term/src/commands/lsp.rs b/helix-term/src/commands/lsp.rs index 578eb608..d12aa436 100644 --- a/helix-term/src/commands/lsp.rs +++ b/helix-term/src/commands/lsp.rs @@ -914,6 +914,31 @@ fn to_locations(definitions: Option<lsp::GotoDefinitionResponse>) -> Vec<lsp::Lo } } +pub fn goto_declaration(cx: &mut Context) { + let (view, doc) = current!(cx.editor); + let language_server = language_server!(cx.editor, doc); + let offset_encoding = language_server.offset_encoding(); + + let pos = doc.position(view.id, offset_encoding); + + let future = match language_server.goto_declaration(doc.identifier(), pos, None) { + Some(future) => future, + None => { + cx.editor + .set_error("Language server does not support goto-declaration"); + return; + } + }; + + cx.callback( + future, + move |editor, compositor, response: Option<lsp::GotoDefinitionResponse>| { + let items = to_locations(response); + goto_impl(editor, compositor, items, offset_encoding); + }, + ); +} + pub fn goto_definition(cx: &mut Context) { let (view, doc) = current!(cx.editor); let language_server = language_server!(cx.editor, doc); |