on master help sign in
gotodefiniton now runs but doesnt return anything
commit8a68a043400342a02496c4ff622dd86e6f40a89c authorJan Hrastnik <jan.hrastnik2@gmail.com> dateSun 21 Feb 2021, 23:43 (6 years ago) parentd3ddc8d
2 files changed+25−2
helix-lsp/src/client.rs+4−1 helix-term/src/commands.rs+21−1
helix-lsp/src/client.rs+4−1
@@ -603,6 +603,8 @@ impl Client {
603603
604604 let response = self.request::<lsp::request::GotoDefinition>(params).await?;
605605
606+ println!("{:?}", response);
607+
606608 let items = match response {
607609 Some(lsp::GotoDefinitionResponse::Scalar(location)) => vec![location],
608610 Some(lsp::GotoDefinitionResponse::Array(location_vec)) => location_vec,
@@ -613,10 +615,11 @@ impl Client {
613615 uri: location_link.target_uri,
614616 range: location_link.target_range,
615617 };
616− location_vec.append(&mut link);
618+ location_vec.push(link)
617619 });
618620 location_vec
619621 }
622+ None => Vec::new(),
620623 };
621624
622625 Ok(items)
helix-term/src/commands.rs+21−1
@@ -846,7 +846,27 @@ pub fn exit_select_mode(cx: &mut Context) {
846846 cx.doc().mode = Mode::Normal;
847847}
848848
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+}
850870
851871// NOTE: Transactions in this module get appended to history when we switch back to normal mode.
852872pub mod insert {