Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

agent_ui: Make rust-analyzer paths work with symbol completions (#46739)

Lukas Wirth1b416c71d64f
diff --git a/crates/agent_ui/Cargo.toml b/crates/agent_ui/Cargo.toml
index 66fd7295a05..997f2bf5ef8 100644
--- a/crates/agent_ui/Cargo.toml
+++ b/crates/agent_ui/Cargo.toml
@@ -13,7 +13,18 @@ path = "src/agent_ui.rs"
doctest = false
[features]
-test-support = ["assistant_text_thread/test-support", "acp_thread/test-support", "eval_utils", "gpui/test-support", "language/test-support", "reqwest_client", "workspace/test-support", "agent/test-support", "rules_library/test-support"]
+test-support = [
+ "assistant_text_thread/test-support",
+ "acp_thread/test-support",
+ "eval_utils",
+ "gpui/test-support",
+ "git_ui/test-support",
+ "language/test-support",
+ "reqwest_client",
+ "workspace/test-support",
+ "agent/test-support",
+ "rules_library/test-support"
+]
unit-eval = []
[dependencies]
@@ -116,6 +127,8 @@ db = { workspace = true, features = ["test-support"] }
editor = { workspace = true, features = ["test-support"] }
eval_utils.workspace = true
gpui = { workspace = true, "features" = ["test-support"] }
+git_ui = { workspace = true, features = ["test-support"] }
+rules_library = { workspace = true, features = ["test-support"] }
indoc.workspace = true
language = { workspace = true, "features" = ["test-support"] }
languages = { workspace = true, features = ["test-support"] }
diff --git a/crates/agent_ui/src/completion_provider.rs b/crates/agent_ui/src/completion_provider.rs
index e866f453936..6eb3a559e8e 100644
--- a/crates/agent_ui/src/completion_provider.rs
+++ b/crates/agent_ui/src/completion_provider.rs
@@ -1556,7 +1556,15 @@ pub(crate) fn search_symbols(
SymbolLocation::OutsideProject { .. } => false,
})
});
-
+ // Try to support rust-analyzer's path based symbols feature which
+ // allows to search by rust path syntax, in that case we only want to
+ // filter names by the last segment
+ // Ideally this was a first class LSP feature (rich queries)
+ let query = query
+ .rsplit_once("::")
+ .map_or(&*query, |(_, suffix)| suffix)
+ .to_owned();
+ // Note if you make changes to this filtering below, also change `project_symbols::ProjectSymbolsDelegate::filter`
const MAX_MATCHES: usize = 100;
let mut visible_matches = cx.background_executor().block(fuzzy::match_strings(
&visible_match_candidates,
@@ -2012,6 +2020,19 @@ mod tests {
})
);
+ assert_eq!(
+ MentionCompletion::try_parse(
+ "Lorem @symbol agent_ui::completion_provider",
+ 0,
+ &supported_modes
+ ),
+ Some(MentionCompletion {
+ source_range: 6..43,
+ mode: Some(PromptContextType::Symbol),
+ argument: Some("agent_ui::completion_provider".to_string()),
+ })
+ );
+
// Disallowed non-file mentions
assert_eq!(
MentionCompletion::try_parse("Lorem @symbol main", 0, &[PromptContextType::File]),
diff --git a/crates/project_symbols/src/project_symbols.rs b/crates/project_symbols/src/project_symbols.rs
index 4c077cb69f5..3a8c60ef43f 100644
--- a/crates/project_symbols/src/project_symbols.rs
+++ b/crates/project_symbols/src/project_symbols.rs
@@ -61,6 +61,7 @@ impl ProjectSymbolsDelegate {
}
}
+ // Note if you make changes to this, also change `agent_ui::completion_provider::search_symbols`
fn filter(&mut self, query: &str, window: &mut Window, cx: &mut Context<Picker<Self>>) {
const MAX_MATCHES: usize = 100;
let mut visible_matches = cx.background_executor().block(fuzzy::match_strings(