diff options
author | Jan Hrastnik | 2021-02-27 23:39:13 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-03-16 14:03:10 +0000 |
commit | 294791dffd707d0725db5eb35b5165fd1bb2c24a (patch) | |
tree | cae1119e449f14d9a0732699eb79d18855caa2b5 /helix-term | |
parent | 0322c28e6bc1f3bf13842b7db47aafbe5752d45c (diff) |
added picker for gd, but yet to test it. also need to load appropriate file when definition isnt in same file
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index b2809f96..f07a3933 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -861,15 +861,42 @@ pub fn goto_definition(cx: &mut Context) { let res = smol::block_on(language_server.goto_definition(doc.identifier(), pos)).unwrap_or_default(); + /* if res.len() == 1 { let definition_pos = res.get(0).unwrap().range.start; let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos); doc.set_selection(Selection::point(new_pos)); } else { // show menu picker i guess - } + }*/ doc.mode = Mode::Normal; + + match &res.as_slice() { + [location] => { + let definition_pos = location.range.start; + let new_pos = helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos); + doc.set_selection(Selection::point(new_pos)); + } + [] => (), // maybe show user message that no definition was found? + _ => { + let snapshot = doc.state.clone(); + let mut picker = ui::Picker::new( + res, + |item| { + let file = item.uri.as_str(); + let line = item.range.start.line.to_string(); + format!("{}:{}", file, line).into() + }, + move |editor: &mut Editor, item| { + let doc = &mut editor.view_mut().doc; + + // revert state to what it was before the last update + doc.state = snapshot.clone(); + }, + ); + } + } } // NOTE: Transactions in this module get appended to history when we switch back to normal mode. |