on master help sign in
gotodefiniton now runs but doesnt return anything
8a68a04Jan Hrastnik
helix-lsp/src/client.rs+4−1
@@ -603,6 +603,8 @@ impl Client {
603
603
604 let response = self.request::<lsp::request::GotoDefinition>(params).await?;
604 let response = self.request::<lsp::request::GotoDefinition>(params).await?;
605
605
606+ println!("{:?}", response);
607+
606 let items = match response {
608 let items = match response {
607 Some(lsp::GotoDefinitionResponse::Scalar(location)) => vec![location],
609 Some(lsp::GotoDefinitionResponse::Scalar(location)) => vec![location],
608 Some(lsp::GotoDefinitionResponse::Array(location_vec)) => location_vec,
610 Some(lsp::GotoDefinitionResponse::Array(location_vec)) => location_vec,
@@ -613,10 +615,11 @@ impl Client {
613 uri: location_link.target_uri,
615 uri: location_link.target_uri,
614 range: location_link.target_range,
616 range: location_link.target_range,
615 };
617 };
616− location_vec.append(&mut link);
618+ location_vec.push(link)
617 });
619 });
618 location_vec
620 location_vec
619 }
621 }
622+ None => Vec::new(),
620 };
623 };
621
624
622 Ok(items)
625 Ok(items)
helix-term/src/commands.rs+21−1
@@ -846,7 +846,27 @@ pub fn exit_select_mode(cx: &mut Context) {
846 cx.doc().mode = Mode::Normal;
846 cx.doc().mode = Mode::Normal;
847}
847}
848
848
849−pub fn goto_definition(cx: &mut Context) {}
849+pub fn goto_definition(cx: &mut Context) {
850+ let language_server = cx
851+ .editor
852+ .language_servers
853+ .get("source.rust", &cx.executor)
854+ .unwrap();
855+ use log::info;
856+
857+ let doc = cx.doc();
858+
859+ // TODO: blocking here is not ideal
860+ let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor());
861+
862+ // TODO: handle fails
863+ let res = smol::block_on(language_server.goto_definition(cx.doc().identifier(), pos))
864+ .unwrap_or_default();
865+
866+ println!("{:?}", res);
867+
868+ cx.doc().mode = Mode::Normal;
869+}
850
870
851// NOTE: Transactions in this module get appended to history when we switch back to normal mode.
871// NOTE: Transactions in this module get appended to history when we switch back to normal mode.
852pub mod insert {
872pub mod insert {