Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
agent_ui: Add file name and line number to symbol completions (#40508)
Paweł Kondziord00ad02b0598
diff --git a/crates/agent_ui/src/acp/completion_provider.rs b/crates/agent_ui/src/acp/completion_provider.rsindex c5ab47fe189..2dac9fc563e 100644--- a/crates/agent_ui/src/acp/completion_provider.rs+++ b/crates/agent_ui/src/acp/completion_provider.rs@@ -253,17 +253,22 @@ impl ContextPickerCompletionProvider {) -> Option<Completion> {let project = workspace.read(cx).project().clone();- let label = CodeLabel::plain(symbol.name.clone(), None);-- let abs_path = match &symbol.path {- SymbolLocation::InProject(project_path) => {- project.read(cx).absolute_path(&project_path, cx)?- }+ let (abs_path, file_name) = match &symbol.path {+ SymbolLocation::InProject(project_path) => (+ project.read(cx).absolute_path(&project_path, cx)?,+ project_path.path.file_name()?.to_string().into(),+ ),SymbolLocation::OutsideProject {abs_path,signature: _,- } => PathBuf::from(abs_path.as_ref()),+ } => (+ PathBuf::from(abs_path.as_ref()),+ abs_path.file_name().map(|f| f.to_string_lossy())?,+ ),};++ let label = build_symbol_label(&symbol.name, &file_name, symbol.range.start.0.row + 1, cx);+let uri = MentionUri::Symbol {abs_path,name: symbol.name.clone(),@@ -674,6 +679,17 @@ impl ContextPickerCompletionProvider {}}+fn build_symbol_label(symbol_name: &str, file_name: &str, line: u32, cx: &App) -> CodeLabel {+ let comment_id = cx.theme().syntax().highlight_id("comment").map(HighlightId);+ let mut label = CodeLabelBuilder::default();++ label.push_str(symbol_name, None);+ label.push_str(" ", None);+ label.push_str(&format!("{} L{}", file_name, line), comment_id);++ label.build()+}+fn build_code_label_for_full_path(file_name: &str, directory: Option<&str>, cx: &App) -> CodeLabel {let comment_id = cx.theme().syntax().highlight_id("comment").map(HighlightId);let mut label = CodeLabelBuilder::default();diff --git a/crates/agent_ui/src/acp/message_editor.rs b/crates/agent_ui/src/acp/message_editor.rsindex 91e9850b082..6bedb61171b 100644--- a/crates/agent_ui/src/acp/message_editor.rs+++ b/crates/agent_ui/src/acp/message_editor.rs@@ -2473,7 +2473,7 @@ mod tests {format!("Lorem [@one.txt]({url_one}) Ipsum [@eight.txt]({url_eight}) @symbol "));assert!(editor.has_visible_completions_menu());- assert_eq!(current_completion_labels(editor), &["MySymbol"]);+ assert_eq!(current_completion_labels(editor), &["MySymbol one.txt L1"]);});editor.update_in(&mut cx, |editor, window, cx| {