Fall back to FindAllReferences if cmd-click did not preform GoToDefinition elsewhere (#9243)
This commit is contained in:
+51
-33
@@ -7610,36 +7610,52 @@ impl Editor {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn go_to_definition(&mut self, _: &GoToDefinition, cx: &mut ViewContext<Self>) {
|
||||
self.go_to_definition_of_kind(GotoDefinitionKind::Symbol, false, cx);
|
||||
pub fn go_to_definition(
|
||||
&mut self,
|
||||
_: &GoToDefinition,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Task<Result<bool>> {
|
||||
self.go_to_definition_of_kind(GotoDefinitionKind::Symbol, false, cx)
|
||||
}
|
||||
|
||||
pub fn go_to_implementation(&mut self, _: &GoToImplementation, cx: &mut ViewContext<Self>) {
|
||||
self.go_to_definition_of_kind(GotoDefinitionKind::Implementation, false, cx);
|
||||
pub fn go_to_implementation(
|
||||
&mut self,
|
||||
_: &GoToImplementation,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Task<Result<bool>> {
|
||||
self.go_to_definition_of_kind(GotoDefinitionKind::Implementation, false, cx)
|
||||
}
|
||||
|
||||
pub fn go_to_implementation_split(
|
||||
&mut self,
|
||||
_: &GoToImplementationSplit,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.go_to_definition_of_kind(GotoDefinitionKind::Implementation, true, cx);
|
||||
) -> Task<Result<bool>> {
|
||||
self.go_to_definition_of_kind(GotoDefinitionKind::Implementation, true, cx)
|
||||
}
|
||||
|
||||
pub fn go_to_type_definition(&mut self, _: &GoToTypeDefinition, cx: &mut ViewContext<Self>) {
|
||||
self.go_to_definition_of_kind(GotoDefinitionKind::Type, false, cx);
|
||||
pub fn go_to_type_definition(
|
||||
&mut self,
|
||||
_: &GoToTypeDefinition,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Task<Result<bool>> {
|
||||
self.go_to_definition_of_kind(GotoDefinitionKind::Type, false, cx)
|
||||
}
|
||||
|
||||
pub fn go_to_definition_split(&mut self, _: &GoToDefinitionSplit, cx: &mut ViewContext<Self>) {
|
||||
self.go_to_definition_of_kind(GotoDefinitionKind::Symbol, true, cx);
|
||||
pub fn go_to_definition_split(
|
||||
&mut self,
|
||||
_: &GoToDefinitionSplit,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) -> Task<Result<bool>> {
|
||||
self.go_to_definition_of_kind(GotoDefinitionKind::Symbol, true, cx)
|
||||
}
|
||||
|
||||
pub fn go_to_type_definition_split(
|
||||
&mut self,
|
||||
_: &GoToTypeDefinitionSplit,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
self.go_to_definition_of_kind(GotoDefinitionKind::Type, true, cx);
|
||||
) -> Task<Result<bool>> {
|
||||
self.go_to_definition_of_kind(GotoDefinitionKind::Type, true, cx)
|
||||
}
|
||||
|
||||
fn go_to_definition_of_kind(
|
||||
@@ -7647,16 +7663,16 @@ impl Editor {
|
||||
kind: GotoDefinitionKind,
|
||||
split: bool,
|
||||
cx: &mut ViewContext<Self>,
|
||||
) {
|
||||
) -> Task<Result<bool>> {
|
||||
let Some(workspace) = self.workspace() else {
|
||||
return;
|
||||
return Task::ready(Ok(false));
|
||||
};
|
||||
let buffer = self.buffer.read(cx);
|
||||
let head = self.selections.newest::<usize>(cx).head();
|
||||
let (buffer, head) = if let Some(text_anchor) = buffer.text_anchor_for_position(head, cx) {
|
||||
text_anchor
|
||||
} else {
|
||||
return;
|
||||
return Task::ready(Ok(false));
|
||||
};
|
||||
|
||||
let project = workspace.read(cx).project().clone();
|
||||
@@ -7668,17 +7684,18 @@ impl Editor {
|
||||
|
||||
cx.spawn(|editor, mut cx| async move {
|
||||
let definitions = definitions.await?;
|
||||
editor.update(&mut cx, |editor, cx| {
|
||||
editor.navigate_to_hover_links(
|
||||
Some(kind),
|
||||
definitions.into_iter().map(HoverLink::Text).collect(),
|
||||
split,
|
||||
cx,
|
||||
);
|
||||
})?;
|
||||
Ok::<(), anyhow::Error>(())
|
||||
let navigated = editor
|
||||
.update(&mut cx, |editor, cx| {
|
||||
editor.navigate_to_hover_links(
|
||||
Some(kind),
|
||||
definitions.into_iter().map(HoverLink::Text).collect(),
|
||||
split,
|
||||
cx,
|
||||
)
|
||||
})?
|
||||
.await?;
|
||||
anyhow::Ok(navigated)
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
}
|
||||
|
||||
pub fn open_url(&mut self, _: &OpenUrl, cx: &mut ViewContext<Self>) {
|
||||
@@ -7707,7 +7724,7 @@ impl Editor {
|
||||
mut definitions: Vec<HoverLink>,
|
||||
split: bool,
|
||||
cx: &mut ViewContext<Editor>,
|
||||
) {
|
||||
) -> Task<Result<bool>> {
|
||||
// If there is one definition, just open it directly
|
||||
if definitions.len() == 1 {
|
||||
let definition = definitions.pop().unwrap();
|
||||
@@ -7726,7 +7743,7 @@ impl Editor {
|
||||
if let Some(target) = target {
|
||||
editor.update(&mut cx, |editor, cx| {
|
||||
let Some(workspace) = editor.workspace() else {
|
||||
return;
|
||||
return false;
|
||||
};
|
||||
let pane = workspace.read(cx).active_pane().clone();
|
||||
|
||||
@@ -7763,12 +7780,12 @@ impl Editor {
|
||||
});
|
||||
});
|
||||
}
|
||||
true
|
||||
})
|
||||
} else {
|
||||
Ok(())
|
||||
Ok(false)
|
||||
}
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
} else if !definitions.is_empty() {
|
||||
let replica_id = self.replica_id(cx);
|
||||
cx.spawn(|editor, mut cx| async move {
|
||||
@@ -7817,9 +7834,9 @@ impl Editor {
|
||||
.context("location tasks")?;
|
||||
|
||||
let Some(workspace) = workspace else {
|
||||
return Ok(());
|
||||
return Ok(false);
|
||||
};
|
||||
workspace
|
||||
let opened = workspace
|
||||
.update(&mut cx, |workspace, cx| {
|
||||
Self::open_locations_in_multibuffer(
|
||||
workspace, locations, replica_id, title, split, cx,
|
||||
@@ -7827,9 +7844,10 @@ impl Editor {
|
||||
})
|
||||
.ok();
|
||||
|
||||
anyhow::Ok(())
|
||||
anyhow::Ok(opened.is_some())
|
||||
})
|
||||
.detach_and_log_err(cx);
|
||||
} else {
|
||||
Task::ready(Ok(false))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user