on master help sign in
wip
commitd3ddc8dea6844f836199196c44b08e63fdf837d0 authorJan Hrastnik <jan.hrastnik2@gmail.com> dateSun 21 Feb 2021, 23:22 (6 years ago) parentd8599f3
5 files changed+48−2
helix-lsp/src/client.rs+39 helix-term/helix.log helix-term/src/commands.rs+2 helix-term/src/keymap.rs+6−2 helix-term/test2.txt+1
helix-lsp/src/client.rs+39
@@ -582,4 +582,43 @@ impl Client {
582582
583583 Ok(response.unwrap_or_default())
584584 }
585+
586+ pub async fn goto_definition(
587+ &self,
588+ text_document: lsp::TextDocumentIdentifier,
589+ position: lsp::Position,
590+ ) -> anyhow::Result<Vec<lsp::Location>> {
591+ let params = lsp::GotoDefinitionParams {
592+ text_document_position_params: lsp::TextDocumentPositionParams {
593+ text_document,
594+ position,
595+ },
596+ work_done_progress_params: lsp::WorkDoneProgressParams {
597+ work_done_token: None,
598+ },
599+ partial_result_params: lsp::PartialResultParams {
600+ partial_result_token: None,
601+ },
602+ };
603+
604+ let response = self.request::<lsp::request::GotoDefinition>(params).await?;
605+
606+ let items = match response {
607+ Some(lsp::GotoDefinitionResponse::Scalar(location)) => vec![location],
608+ Some(lsp::GotoDefinitionResponse::Array(location_vec)) => location_vec,
609+ Some(lsp::GotoDefinitionResponse::Link(location_link_vec)) => {
610+ let mut location_vec: Vec<lsp::Location> = Vec::new();
611+ location_link_vec.into_iter().for_each(|location_link| {
612+ let link = lsp::Location {
613+ uri: location_link.target_uri,
614+ range: location_link.target_range,
615+ };
616+ location_vec.append(&mut link);
617+ });
618+ location_vec
619+ }
620+ };
621+
622+ Ok(items)
623+ }
585624}
helix-term/helix.lognew file

No changes to the content.

helix-term/src/commands.rs+2
@@ -846,6 +846,8 @@ pub fn exit_select_mode(cx: &mut Context) {
846846 cx.doc().mode = Mode::Normal;
847847}
848848
849+pub fn goto_definition(cx: &mut Context) {}
850+
849851// NOTE: Transactions in this module get appended to history when we switch back to normal mode.
850852pub mod insert {
851853 use super::*;
helix-term/src/keymap.rs+6−2
@@ -311,8 +311,12 @@ pub fn default() -> Keymaps {
311311 code: KeyCode::Esc,
312312 modifiers: Modifiers::NONE
313313 } => commands::normal_mode as Command,
314− key!('g') => commands::move_file_start as Command,
315− key!('e') => commands::move_file_end as Command,
314+ key!('g') => commands::move_file_start,
315+ key!('e') => commands::move_file_end,
316+ key!('d') => commands::goto_definition,
317+ key!('t') => commands::goto_type_definition,
318+ key!('r') => commands::goto_reference,
319+ key!('i') => commands::goto_implementation,
316320 ),
317321 )
318322}
helix-term/test2.txtnew file+1
@@ -0,0 +1 @@
1+awdwadwadwa njvkrnvjre eahdwau kjvreng