on master help sign in
added picker for gd, but yet to test it. also need to load appropriate file when definition isnt in same file
commit294791dffd707d0725db5eb35b5165fd1bb2c24a authorJan Hrastnik <jan.hrastnik2@gmail.com> dateSun 28 Feb 2021, 00:39 (6 years ago) parent0322c28
1 file changed+28−1
helix-term/src/commands.rs+28−1
helix-term/src/commands.rs+28−1
@@ -861,15 +861,42 @@ pub fn goto_definition(cx: &mut Context) {
861861 let res =
862862 smol::block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default();
863863
864+ /*
864865 if res.len() == 1 {
865866 let definition_pos = res.get(0).unwrap().range.start;
866867 let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos);
867868 doc.set_selection(Selection::point(new_pos));
868869 } else {
869870 // show menu picker i guess
870− }
871+ }*/
871872
872873 doc.mode = Mode::Normal;
874+
875+ match &res.as_slice() {
876+ [location] => {
877+ let definition_pos = location.range.start;
878+ let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos);
879+ doc.set_selection(Selection::point(new_pos));
880+ }
881+ [] => (), // maybe show user message that no definition was found?
882+ _ => {
883+ let snapshot = doc.state.clone();
884+ let mut picker = ui::Picker::new(
885+ res,
886+ |item| {
887+ let file = item.uri.as_str();
888+ let line = item.range.start.line.to_string();
889+ format!("{}:{}", file, line).into()
890+ },
891+ move |editor: &mut Editor, item| {
892+ let doc = &mut editor.view_mut().doc;
893+
894+ // revert state to what it was before the last update
895+ doc.state = snapshot.clone();
896+ },
897+ );
898+ }
899+ }
873900}
874901
875902// NOTE: Transactions in this module get appended to history when we switch back to normal mode.