on master help sign in
Fix goto code before merging.
e3ec5e3Blaž Hrastnik
helix-term/src/commands.rs+1−3
@@ -15,8 +15,6 @@ use crate::ui::{self, Popup, Prompt, PromptEvent};
15
15
16use std::path::PathBuf;
16use std::path::PathBuf;
17
17
18−use smol::Executor;
19−
20use helix_view::{
18use helix_view::{
21 document::Mode,
19 document::Mode,
22 view::{View, PADDING},
20 view::{View, PADDING},
@@ -853,6 +851,7 @@ pub fn exit_select_mode(cx: &mut Context) {
853}
851}
854
852
855fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
853fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
854+ let executor = cx.executor;
856 let doc = cx.doc();
855 let doc = cx.doc();
857
856
858 doc.mode = Mode::Normal;
857 doc.mode = Mode::Normal;
@@ -876,7 +875,6 @@ fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
876 format!("{}:{}", file, line).into()
875 format!("{}:{}", file, line).into()
877 },
876 },
878 move |editor: &mut Editor, item| {
877 move |editor: &mut Editor, item| {
879− let executor = smol::Executor::new();
880 editor.open(PathBuf::from(item.uri.path()), &executor);
878 editor.open(PathBuf::from(item.uri.path()), &executor);
881 let mut doc = &mut editor.view_mut().doc;
879 let mut doc = &mut editor.view_mut().doc;
882 let definition_pos = item.range.start;
880 let definition_pos = item.range.start;
helix-view/src/editor.rs+5−5
@@ -33,13 +33,13 @@ impl Editor {
33 }
33 }
34
34
35 pub fn open(&mut self, path: PathBuf, executor: &smol::Executor) -> Result<(), Error> {
35 pub fn open(&mut self, path: PathBuf, executor: &smol::Executor) -> Result<(), Error> {
36− // TODO: try to find an open view/buffer first
36+ let existing_view = self
37− let existing_view_option = self
38 .tree
37 .tree
39 .views()
38 .views()
40− .find(|v| path.to_str().unwrap() == v.0.doc.path().unwrap().to_str().unwrap());
39+ .find(|(view, _)| view.doc.path() == Some(&path));
41− if let Some(existing_view) = existing_view_option {
40+
41+ if let Some((view, _)) = existing_view {
42− self.tree.focus = existing_view.0.id;
42+ self.tree.focus = view.id;
43 return Ok(());
43 return Ok(());
44 }
44 }
45
45