Add a way to control go to definition fallback (#27426)

Follow-up of https://github.com/zed-industries/zed/pull/9243 and
https://github.com/zed-industries/zed/pull/16512

Release Notes:

- Added a way to control go to definition fallback
This commit is contained in:
Kirill Bulatov 2025-03-26 00:13:35 +02:00 committed by GitHub
parent 8c8f50d916
commit 30f7e896cf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 107 additions and 7 deletions

View file

@ -60,6 +60,7 @@ use collections::{BTreeMap, HashMap, HashSet, VecDeque};
use convert_case::{Case, Casing};
use display_map::*;
pub use display_map::{DisplayPoint, FoldPlaceholder};
use editor_settings::GoToDefinitionFallback;
pub use editor_settings::{
CurrentLineHighlight, EditorSettings, ScrollBeyondLastLine, SearchSettings, ShowScrollbar,
};
@ -12662,15 +12663,21 @@ impl Editor {
) -> Task<Result<Navigated>> {
let definition =
self.go_to_definition_of_kind(GotoDefinitionKind::Symbol, false, window, cx);
let fallback_strategy = EditorSettings::get_global(cx).go_to_definition_fallback;
cx.spawn_in(window, async move |editor, cx| {
if definition.await? == Navigated::Yes {
return Ok(Navigated::Yes);
}
match editor.update_in(cx, |editor, window, cx| {
editor.find_all_references(&FindAllReferences, window, cx)
})? {
Some(references) => references.await,
None => Ok(Navigated::No),
match fallback_strategy {
GoToDefinitionFallback::None => Ok(Navigated::No),
GoToDefinitionFallback::FindAllReferences => {
match editor.update_in(cx, |editor, window, cx| {
editor.find_all_references(&FindAllReferences, window, cx)
})? {
Some(references) => references.await,
None => Ok(Navigated::No),
}
}
}
})
}