Make "go to definition" work in project diagnostics

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra
2022-01-20 17:30:30 +01:00
co-authored by Nathan Sobo
parent d92b40474f
commit b6685a532c
9 changed files with 79 additions and 37 deletions
+11 -6
View File
@@ -2992,11 +2992,17 @@ impl Editor {
_: &GoToDefinition,
cx: &mut ViewContext<Workspace>,
) {
let editor = workspace
.active_item(cx)
.and_then(|item| item.to_any().downcast::<Self>())
.unwrap()
.read(cx);
let active_item = workspace.active_item(cx);
let editor = if let Some(editor) = active_item
.as_ref()
.and_then(|item| item.act_as::<Self>(cx))
{
editor
} else {
return;
};
let editor = editor.read(cx);
let buffer = editor.buffer.read(cx);
let head = editor.newest_selection::<usize>(&buffer.read(cx)).head();
let (buffer, head) = editor.buffer.read(cx).text_anchor_for_position(head, cx);
@@ -3012,7 +3018,6 @@ impl Editor {
.to_offset(definition.target_buffer.read(cx));
let target_editor = workspace
.open_item(BufferItemHandle(definition.target_buffer), cx)
.to_any()
.downcast::<Self>()
.unwrap();
target_editor.update(cx, |target_editor, cx| {
+2 -2
View File
@@ -279,7 +279,7 @@ impl StatusItemView for CursorPosition {
active_pane_item: Option<&dyn ItemViewHandle>,
cx: &mut ViewContext<Self>,
) {
if let Some(editor) = active_pane_item.and_then(|item| item.to_any().downcast::<Editor>()) {
if let Some(editor) = active_pane_item.and_then(|item| item.downcast::<Editor>()) {
self._observe_active_editor = Some(cx.observe(&editor, Self::update_position));
self.update_position(editor, cx);
} else {
@@ -365,7 +365,7 @@ impl StatusItemView for DiagnosticMessage {
active_pane_item: Option<&dyn ItemViewHandle>,
cx: &mut ViewContext<Self>,
) {
if let Some(editor) = active_pane_item.and_then(|item| item.to_any().downcast::<Editor>()) {
if let Some(editor) = active_pane_item.and_then(|item| item.downcast::<Editor>()) {
self._observe_active_editor = Some(cx.observe(&editor, Self::update));
self.update(editor, cx);
} else {