on master help sign in
Simplify code a bit.
18ec8adBlaž Hrastnik
helix-term/src/commands.rs+8−12
@@ -847,25 +847,21 @@ pub fn exit_select_mode(cx: &mut Context) {
847}
847}
848
848
849pub fn goto_definition(cx: &mut Context) {
849pub 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();
850 let doc = cx.doc();
858
851
852+ let language_server = match doc.language_server.as_ref() {
853+ Some(language_server) => language_server,
854+ None => return,
855+ };
856+
859 // TODO: blocking here is not ideal
857 // TODO: blocking here is not ideal
860 let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor());
858 let pos = helix_lsp::util::pos_to_lsp_pos(doc.text().slice(..), doc.selection().cursor());
861
859
862 // TODO: handle fails
860 // TODO: handle fails
861+ let res =
863− let res = smol::block_on(language_server.goto_definition(cx.doc().identifier(), pos))
862+ smol::block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default();
864− .unwrap_or_default();
865−
866− println!("{:?}", res);
867
863
868− cx.doc().mode = Mode::Normal;
864+ doc.mode = Mode::Normal;
869}
865}
870
866
871// NOTE: Transactions in this module get appended to history when we switch back to normal mode.
867// NOTE: Transactions in this module get appended to history when we switch back to normal mode.