Skip to content

Commit

Permalink
editor.open now checks if view already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
janhrastnik authored and archseer committed Mar 16, 2021
1 parent 0828d1f commit 4e461be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
15 changes: 8 additions & 7 deletions helix-term/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ pub fn exit_select_mode(cx: &mut Context) {
cx.doc().mode = Mode::Normal;
}

fn goto(cx: &'static mut Context<'static>, locations: Vec<lsp::Location>) {
fn goto(cx: &mut Context, locations: Vec<lsp::Location>) {
let doc = cx.doc();

doc.mode = Mode::Normal;
Expand All @@ -878,8 +878,9 @@ fn goto(cx: &'static mut Context<'static>, locations: Vec<lsp::Location>) {
format!("{}:{}", file, line).into()
},
move |editor: &mut Editor, item| {
cx.editor.open(PathBuf::from(item.uri.path()), cx.executor);
let doc = cx.doc();
let executor = smol::Executor::new();
editor.open(PathBuf::from(item.uri.path()), &executor);
let mut doc = &mut editor.view_mut().doc;
let definition_pos = item.range.start;
let new_pos =
helix_lsp::util::lsp_pos_to_pos(doc.text().slice(..), definition_pos);
Expand All @@ -891,7 +892,7 @@ fn goto(cx: &'static mut Context<'static>, locations: Vec<lsp::Location>) {
}
}

pub fn goto_definition(cx: &'static mut Context<'static>) {
pub fn goto_definition(cx: &mut Context) {
let doc = cx.doc();
let language_server = match doc.language_server.as_ref() {
Some(language_server) => language_server,
Expand All @@ -907,7 +908,7 @@ pub fn goto_definition(cx: &'static mut Context<'static>) {
goto(cx, res);
}

pub fn goto_type_definition(cx: &'static mut Context<'static>) {
pub fn goto_type_definition(cx: &mut Context) {
let doc = cx.doc();
let language_server = match doc.language_server.as_ref() {
Some(language_server) => language_server,
Expand All @@ -923,7 +924,7 @@ pub fn goto_type_definition(cx: &'static mut Context<'static>) {
goto(cx, res);
}

pub fn goto_implementation(cx: &'static mut Context<'static>) {
pub fn goto_implementation(cx: &mut Context) {
let doc = cx.doc();
let language_server = match doc.language_server.as_ref() {
Some(language_server) => language_server,
Expand All @@ -939,7 +940,7 @@ pub fn goto_implementation(cx: &'static mut Context<'static>) {
goto(cx, res);
}

pub fn goto_reference(cx: &'static mut Context<'static>) {
pub fn goto_reference(cx: &mut Context) {
let doc = cx.doc();
let language_server = match doc.language_server.as_ref() {
Some(language_server) => language_server,
Expand Down
10 changes: 9 additions & 1 deletion helix-view/src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,15 @@ impl Editor {
}

let view = View::new(doc)?;
self.tree.insert(view);
let existing_view_option = self
.tree
.views()
.find(|v| view.doc.path().unwrap().to_str() == v.0.doc.path().unwrap().to_str());
if let Some(existing_view) = existing_view_option {
self.tree.focus = existing_view.0.id;
} else {
self.tree.insert(view);
}
Ok(())
}

Expand Down

0 comments on commit 4e461be

Please sign in to comment.