From b6914bf0fda2e04415db3b2f4d26650e89a3b71d Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Tue, 14 Nov 2023 16:09:29 +0100 Subject: [PATCH] Re-enable find all references Co-Authored-By: Julia --- crates/editor2/src/editor.rs | 84 ++++++++++++++++------------------- crates/editor2/src/element.rs | 6 ++- 2 files changed, 44 insertions(+), 46 deletions(-) diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rs index 22ceea51a3..d02521fac1 100644 --- a/crates/editor2/src/editor.rs +++ b/crates/editor2/src/editor.rs @@ -7588,53 +7588,47 @@ impl Editor { }) } - // pub fn find_all_references( - // workspace: &mut Workspace, - // _: &FindAllReferences, - // cx: &mut ViewContext, - // ) -> Option>> { - // let active_item = workspace.active_item(cx)?; - // let editor_handle = active_item.act_as::(cx)?; + pub fn find_all_references( + &mut self, + _: &FindAllReferences, + cx: &mut ViewContext, + ) -> Option>> { + let buffer = self.buffer.read(cx); + let head = self.selections.newest::(cx).head(); + let (buffer, head) = buffer.text_anchor_for_position(head, cx)?; + let replica_id = self.replica_id(cx); - // let editor = editor_handle.read(cx); - // let buffer = editor.buffer.read(cx); - // let head = editor.selections.newest::(cx).head(); - // let (buffer, head) = buffer.text_anchor_for_position(head, cx)?; - // let replica_id = editor.replica_id(cx); + let workspace = self.workspace()?; + let project = workspace.read(cx).project().clone(); + let references = project.update(cx, |project, cx| project.references(&buffer, head, cx)); + Some(cx.spawn(|_, mut cx| async move { + let locations = references.await?; + if locations.is_empty() { + return Ok(()); + } - // let project = workspace.project().clone(); - // let references = project.update(cx, |project, cx| project.references(&buffer, head, cx)); - // Some(cx.spawn_labeled( - // "Finding All References...", - // |workspace, mut cx| async move { - // let locations = references.await?; - // if locations.is_empty() { - // return Ok(()); - // } + workspace.update(&mut cx, |workspace, cx| { + let title = locations + .first() + .as_ref() + .map(|location| { + let buffer = location.buffer.read(cx); + format!( + "References to `{}`", + buffer + .text_for_range(location.range.clone()) + .collect::() + ) + }) + .unwrap(); + Self::open_locations_in_multibuffer( + workspace, locations, replica_id, title, false, cx, + ); + })?; - // workspace.update(&mut cx, |workspace, cx| { - // let title = locations - // .first() - // .as_ref() - // .map(|location| { - // let buffer = location.buffer.read(cx); - // format!( - // "References to `{}`", - // buffer - // .text_for_range(location.range.clone()) - // .collect::() - // ) - // }) - // .unwrap(); - // Self::open_locations_in_multibuffer( - // workspace, locations, replica_id, title, false, cx, - // ); - // })?; - - // Ok(()) - // }, - // )) - // } + Ok(()) + })) + } /// Opens a multibuffer with the given project locations in it pub fn open_locations_in_multibuffer( @@ -7685,7 +7679,7 @@ impl Editor { editor.update(cx, |editor, cx| { editor.highlight_background::( ranges_to_highlight, - |theme| todo!("theme.editor.highlighted_line_background"), + |theme| theme.editor_highlighted_line_background, cx, ); }); diff --git a/crates/editor2/src/element.rs b/crates/editor2/src/element.rs index 64a281d9e2..38b54ea2b1 100644 --- a/crates/editor2/src/element.rs +++ b/crates/editor2/src/element.rs @@ -2565,7 +2565,11 @@ impl Element for EditorElement { }); // on_action(cx, Editor::rename); todo!() // on_action(cx, Editor::confirm_rename); todo!() - // on_action(cx, Editor::find_all_references); todo!() + register_action(cx, |editor, action, cx| { + editor + .find_all_references(action, cx) + .map(|task| task.detach_and_log_err(cx)); + }); register_action(cx, Editor::next_copilot_suggestion); register_action(cx, Editor::previous_copilot_suggestion); register_action(cx, Editor::copilot_suggest);