diff options
author | Jan Hrastnik | 2021-03-14 21:24:46 +0000 |
---|---|---|
committer | Blaž Hrastnik | 2021-03-16 14:03:29 +0000 |
commit | 0828d1fdea0b69a2912bc6d550ec50c1b6bf874c (patch) | |
tree | 74f1fe71c3de8408dc72d3a79f14ae4e45721214 /helix-term | |
parent | 15f142bc4b79aa0ef60bea3f0faa2dc49b73505b (diff) |
picker wip
Diffstat (limited to 'helix-term')
-rw-r--r-- | helix-term/src/commands.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/helix-term/src/commands.rs b/helix-term/src/commands.rs index 5a99d795..22a8737f 100644 --- a/helix-term/src/commands.rs +++ b/helix-term/src/commands.rs @@ -852,27 +852,21 @@ pub fn exit_select_mode(cx: &mut Context) { cx.doc().mode = Mode::Normal; } -fn goto(cx: &mut Context, locations: Vec<lsp::Location>) { +fn goto(cx: &'static mut Context<'static>, locations: Vec<lsp::Location>) { let doc = cx.doc(); doc.mode = Mode::Normal; log::info!("{:?}", locations); - let filepath = doc.path().unwrap(); - log::info!("{:?}", filepath); match locations.as_slice() { [location] => { - if filepath.to_str().unwrap() == location.uri.path() { - 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)); - } else { - // open new file - cx.editor - .open(PathBuf::from(location.uri.path()), cx.executor); - // TODO: go to position - } + cx.editor + .open(PathBuf::from(location.uri.path()), cx.executor); + let doc = cx.doc(); + 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? _locations => { @@ -884,14 +878,20 @@ fn goto(cx: &mut Context, locations: Vec<lsp::Location>) { format!("{}:{}", file, line).into() }, move |editor: &mut Editor, item| { - let doc = &mut editor.view_mut().doc; + cx.editor.open(PathBuf::from(item.uri.path()), cx.executor); + let doc = cx.doc(); + let definition_pos = item.range.start; + let new_pos = + helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos); + doc.set_selection(Selection::point(new_pos)); }, ); + cx.push_layer(Box::new(picker)); } } } -pub fn goto_definition(cx: &mut Context) { +pub fn goto_definition(cx: &'static mut Context<'static>) { let doc = cx.doc(); let language_server = match doc.language_server.as_ref() { Some(language_server) => language_server, @@ -907,7 +907,7 @@ pub fn goto_definition(cx: &mut Context) { goto(cx, res); } -pub fn goto_type_definition(cx: &mut Context) { +pub fn goto_type_definition(cx: &'static mut Context<'static>) { let doc = cx.doc(); let language_server = match doc.language_server.as_ref() { Some(language_server) => language_server, @@ -923,7 +923,7 @@ pub fn goto_type_definition(cx: &mut Context) { goto(cx, res); } -pub fn goto_implementation(cx: &mut Context) { +pub fn goto_implementation(cx: &'static mut Context<'static>) { let doc = cx.doc(); let language_server = match doc.language_server.as_ref() { Some(language_server) => language_server, @@ -939,7 +939,7 @@ pub fn goto_implementation(cx: &mut Context) { goto(cx, res); } -pub fn goto_reference(cx: &mut Context) { +pub fn goto_reference(cx: &'static mut Context<'static>) { let doc = cx.doc(); let language_server = match doc.language_server.as_ref() { Some(language_server) => language_server, |