Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Re-enable find all references
Antonio Scandurrab6914bf0fda2
diff --git a/crates/editor2/src/editor.rs b/crates/editor2/src/editor.rsindex 22ceea51a30..d02521fac1d 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<Workspace>,- // ) -> Option<Task<Result<()>>> {- // let active_item = workspace.active_item(cx)?;- // let editor_handle = active_item.act_as::<Self>(cx)?;-- // let editor = editor_handle.read(cx);- // let buffer = editor.buffer.read(cx);- // let head = editor.selections.newest::<usize>(cx).head();- // let (buffer, head) = buffer.text_anchor_for_position(head, cx)?;- // let replica_id = editor.replica_id(cx);-- // 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(());- // }+ pub fn find_all_references(+ &mut self,+ _: &FindAllReferences,+ cx: &mut ViewContext<Self>,+ ) -> Option<Task<Result<()>>> {+ let buffer = self.buffer.read(cx);+ let head = self.selections.newest::<usize>(cx).head();+ let (buffer, head) = buffer.text_anchor_for_position(head, cx)?;+ let replica_id = self.replica_id(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::<String>()- // )- // })- // .unwrap();- // Self::open_locations_in_multibuffer(- // workspace, locations, replica_id, title, false, 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(());+ }++ 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::<String>()+ )+ })+ .unwrap();+ Self::open_locations_in_multibuffer(+ workspace, locations, replica_id, title, false, cx,+ );+ })?;- // Ok(())- // },- // ))- // }+ Ok(())+ }))+ }/// Opens a multibuffer with the given project locations in itpub fn open_locations_in_multibuffer(@@ -7685,7 +7679,7 @@ impl Editor {editor.update(cx, |editor, cx| {editor.highlight_background::<Self>(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.rsindex 64a281d9e26..38b54ea2b15 100644--- a/crates/editor2/src/element.rs+++ b/crates/editor2/src/element.rs@@ -2565,7 +2565,11 @@ impl Element<Editor> 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);