Re-enable find all references

Co-Authored-By: Julia <julia@zed.dev>
This commit is contained in:
Antonio Scandurra 2023-11-14 16:09:29 +01:00
parent f9b9b7549f
commit b6914bf0fd
2 changed files with 44 additions and 46 deletions

View file

@ -7588,53 +7588,47 @@ impl Editor {
}) })
} }
// pub fn find_all_references( pub fn find_all_references(
// workspace: &mut Workspace, &mut self,
// _: &FindAllReferences, _: &FindAllReferences,
// cx: &mut ViewContext<Workspace>, cx: &mut ViewContext<Self>,
// ) -> Option<Task<Result<()>>> { ) -> Option<Task<Result<()>>> {
// let active_item = workspace.active_item(cx)?; let buffer = self.buffer.read(cx);
// let editor_handle = active_item.act_as::<Self>(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);
// let editor = editor_handle.read(cx); let workspace = self.workspace()?;
// let buffer = editor.buffer.read(cx); let project = workspace.read(cx).project().clone();
// let head = editor.selections.newest::<usize>(cx).head(); let references = project.update(cx, |project, cx| project.references(&buffer, head, cx));
// let (buffer, head) = buffer.text_anchor_for_position(head, cx)?; Some(cx.spawn(|_, mut cx| async move {
// let replica_id = editor.replica_id(cx); let locations = references.await?;
if locations.is_empty() {
return Ok(());
}
// let project = workspace.project().clone(); workspace.update(&mut cx, |workspace, cx| {
// let references = project.update(cx, |project, cx| project.references(&buffer, head, cx)); let title = locations
// Some(cx.spawn_labeled( .first()
// "Finding All References...", .as_ref()
// |workspace, mut cx| async move { .map(|location| {
// let locations = references.await?; let buffer = location.buffer.read(cx);
// if locations.is_empty() { format!(
// return Ok(()); "References to `{}`",
// } buffer
.text_for_range(location.range.clone())
.collect::<String>()
)
})
.unwrap();
Self::open_locations_in_multibuffer(
workspace, locations, replica_id, title, false, cx,
);
})?;
// workspace.update(&mut cx, |workspace, cx| { Ok(())
// 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(())
// },
// ))
// }
/// Opens a multibuffer with the given project locations in it /// Opens a multibuffer with the given project locations in it
pub fn open_locations_in_multibuffer( pub fn open_locations_in_multibuffer(
@ -7685,7 +7679,7 @@ impl Editor {
editor.update(cx, |editor, cx| { editor.update(cx, |editor, cx| {
editor.highlight_background::<Self>( editor.highlight_background::<Self>(
ranges_to_highlight, ranges_to_highlight,
|theme| todo!("theme.editor.highlighted_line_background"), |theme| theme.editor_highlighted_line_background,
cx, cx,
); );
}); });

View file

@ -2565,7 +2565,11 @@ impl Element<Editor> for EditorElement {
}); });
// on_action(cx, Editor::rename); todo!() // on_action(cx, Editor::rename); todo!()
// on_action(cx, Editor::confirm_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::next_copilot_suggestion);
register_action(cx, Editor::previous_copilot_suggestion); register_action(cx, Editor::previous_copilot_suggestion);
register_action(cx, Editor::copilot_suggest); register_action(cx, Editor::copilot_suggest);