mirror of
https://github.com/helix-editor/helix
synced 2024-05-03 22:26:07 +02:00
Support goto-declaration LSP command (#5646)
This commit is contained in:
parent
c9b583ea9b
commit
4eca4b3079
|
@ -886,6 +886,31 @@ pub fn goto_definition(
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn goto_declaration(
|
||||||
|
&self,
|
||||||
|
text_document: lsp::TextDocumentIdentifier,
|
||||||
|
position: lsp::Position,
|
||||||
|
work_done_token: Option<lsp::ProgressToken>,
|
||||||
|
) -> Option<impl Future<Output = Result<Value>>> {
|
||||||
|
let capabilities = self.capabilities.get().unwrap();
|
||||||
|
|
||||||
|
// Return early if the server does not support goto-declaration.
|
||||||
|
match capabilities.declaration_provider {
|
||||||
|
Some(
|
||||||
|
lsp::DeclarationCapability::Simple(true)
|
||||||
|
| lsp::DeclarationCapability::RegistrationOptions(_)
|
||||||
|
| lsp::DeclarationCapability::Options(_),
|
||||||
|
) => (),
|
||||||
|
_ => return None,
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(self.goto_request::<lsp::request::GotoDeclaration>(
|
||||||
|
text_document,
|
||||||
|
position,
|
||||||
|
work_done_token,
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn goto_type_definition(
|
pub fn goto_type_definition(
|
||||||
&self,
|
&self,
|
||||||
text_document: lsp::TextDocumentIdentifier,
|
text_document: lsp::TextDocumentIdentifier,
|
||||||
|
|
|
@ -285,6 +285,7 @@ pub fn doc(&self) -> &str {
|
||||||
select_mode, "Enter selection extend mode",
|
select_mode, "Enter selection extend mode",
|
||||||
exit_select_mode, "Exit selection mode",
|
exit_select_mode, "Exit selection mode",
|
||||||
goto_definition, "Goto definition",
|
goto_definition, "Goto definition",
|
||||||
|
goto_declaration, "Goto declaration",
|
||||||
add_newline_above, "Add newline above",
|
add_newline_above, "Add newline above",
|
||||||
add_newline_below, "Add newline below",
|
add_newline_below, "Add newline below",
|
||||||
goto_type_definition, "Goto type definition",
|
goto_type_definition, "Goto type definition",
|
||||||
|
|
|
@ -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) {
|
pub fn goto_definition(cx: &mut Context) {
|
||||||
let (view, doc) = current!(cx.editor);
|
let (view, doc) = current!(cx.editor);
|
||||||
let language_server = language_server!(cx.editor, doc);
|
let language_server = language_server!(cx.editor, doc);
|
||||||
|
|
|
@ -44,6 +44,7 @@ pub fn default() -> HashMap<Mode, Keymap> {
|
||||||
"l" => goto_line_end,
|
"l" => goto_line_end,
|
||||||
"s" => goto_first_nonwhitespace,
|
"s" => goto_first_nonwhitespace,
|
||||||
"d" => goto_definition,
|
"d" => goto_definition,
|
||||||
|
"D" => goto_declaration,
|
||||||
"y" => goto_type_definition,
|
"y" => goto_type_definition,
|
||||||
"r" => goto_reference,
|
"r" => goto_reference,
|
||||||
"i" => goto_implementation,
|
"i" => goto_implementation,
|
||||||
|
|
Loading…
Reference in New Issue