on master help sign in
editor.open now checks if view already exists
4e461beJan Hrastnik
helix-term/src/commands.rs+8−7
@@ -852,7 +852,7 @@ pub fn exit_select_mode(cx: &mut Context) {
852 cx.doc().mode = Mode::Normal;
852 cx.doc().mode = Mode::Normal;
853}
853}
854
854
855−fn goto(cx: &'static mut Context<'static>, locations: Vec<lsp::Location>) {
855+fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
856 let doc = cx.doc();
856 let doc = cx.doc();
857
857
858 doc.mode = Mode::Normal;
858 doc.mode = Mode::Normal;
@@ -878,8 +878,9 @@ fn goto(cx: &'static mut Context<'static>, locations: Vec<lsp::Location>) {
878 format!("{}:{}", file, line).into()
878 format!("{}:{}", file, line).into()
879 },
879 },
880 move |editor: &mut Editor, item| {
880 move |editor: &mut Editor, item| {
881+ let executor = smol::Executor::new();
881− cx.editor.open(PathBuf::from(item.uri.path()), cx.executor);
882+ editor.open(PathBuf::from(item.uri.path()), &executor);
882− let doc = cx.doc();
883+ let mut doc = &mut editor.view_mut().doc;
883 let definition_pos = item.range.start;
884 let definition_pos = item.range.start;
884 let new_pos =
885 let new_pos =
885 helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos);
886 helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos);
@@ -891,7 +892,7 @@ fn goto(cx: &'static mut Context<'static>, locations: Vec<lsp::Location>) {
891 }
892 }
892}
893}
893
894
894−pub fn goto_definition(cx: &'static mut Context<'static>) {
895+pub fn goto_definition(cx: &mut Context) {
895 let doc = cx.doc();
896 let doc = cx.doc();
896 let language_server = match doc.language_server.as_ref() {
897 let language_server = match doc.language_server.as_ref() {
897 Some(language_server) => language_server,
898 Some(language_server) => language_server,
@@ -907,7 +908,7 @@ pub fn goto_definition(cx: &'static mut Context<'static>) {
907 goto(cx, res);
908 goto(cx, res);
908}
909}
909
910
910−pub fn goto_type_definition(cx: &'static mut Context<'static>) {
911+pub fn goto_type_definition(cx: &mut Context) {
911 let doc = cx.doc();
912 let doc = cx.doc();
912 let language_server = match doc.language_server.as_ref() {
913 let language_server = match doc.language_server.as_ref() {
913 Some(language_server) => language_server,
914 Some(language_server) => language_server,
@@ -923,7 +924,7 @@ pub fn goto_type_definition(cx: &'static mut Context<'static>) {
923 goto(cx, res);
924 goto(cx, res);
924}
925}
925
926
926−pub fn goto_implementation(cx: &'static mut Context<'static>) {
927+pub fn goto_implementation(cx: &mut Context) {
927 let doc = cx.doc();
928 let doc = cx.doc();
928 let language_server = match doc.language_server.as_ref() {
929 let language_server = match doc.language_server.as_ref() {
929 Some(language_server) => language_server,
930 Some(language_server) => language_server,
@@ -939,7 +940,7 @@ pub fn goto_implementation(cx: &'static mut Context<'static>) {
939 goto(cx, res);
940 goto(cx, res);
940}
941}
941
942
942−pub fn goto_reference(cx: &'static mut Context<'static>) {
943+pub fn goto_reference(cx: &mut Context) {
943 let doc = cx.doc();
944 let doc = cx.doc();
944 let language_server = match doc.language_server.as_ref() {
945 let language_server = match doc.language_server.as_ref() {
945 Some(language_server) => language_server,
946 Some(language_server) => language_server,
helix-view/src/editor.rs+9−1
@@ -62,7 +62,15 @@ impl Editor {
62 }
62 }
63
63
64 let view = View::new(doc)?;
64 let view = View::new(doc)?;
65+ let existing_view_option = self
66+ .tree
67+ .views()
68+ .find(|v| view.doc.path().unwrap().to_str() == v.0.doc.path().unwrap().to_str());
69+ if let Some(existing_view) = existing_view_option {
70+ self.tree.focus = existing_view.0.id;
71+ } else {
65− self.tree.insert(view);
72+ self.tree.insert(view);
73+ }
66 Ok(())
74 Ok(())
67 }
75 }
68
76