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: Fix selection mentions from "Add to Agent Thread" not opening files (#61621)

ᴀᴍᴛᴏᴀᴇʀ401a0c7e3dee
diff --git a/crates/agent_ui/src/completion_provider.rs b/crates/agent_ui/src/completion_provider.rs
index ff6f4ca13b1..6b6196c4382 100644
--- a/crates/agent_ui/src/completion_provider.rs
+++ b/crates/agent_ui/src/completion_provider.rs
@@ -528,7 +528,14 @@ impl<T: PromptCompletionProviderDelegate> PromptCompletionProvider<T> {
AgentContextSource::from_active(workspace, cx)?
.read_selection(workspace, false, cx)
});
- Self::completion_for_action(action, source_range, editor, mention_set, selection)
+ Self::completion_for_action(
+ action,
+ source_range,
+ editor,
+ mention_set,
+ workspace.downgrade(),
+ selection,
+ )
}
}
}
@@ -815,6 +822,7 @@ impl<T: PromptCompletionProviderDelegate> PromptCompletionProvider<T> {
source_range: Range<Anchor>,
editor: WeakEntity<Editor>,
mention_set: WeakEntity<MentionSet>,
+ workspace: WeakEntity<Workspace>,
selection: Option<AgentContextSelection>,
) -> Option<Completion> {
let (new_text, on_action) = match action {
@@ -824,6 +832,7 @@ impl<T: PromptCompletionProviderDelegate> PromptCompletionProvider<T> {
source_range.clone(),
editor,
mention_set,
+ workspace,
editor_selections,
)
}
@@ -2702,6 +2711,7 @@ fn completion_text_for_editor_selections(
source_range: Range<Anchor>,
editor: WeakEntity<Editor>,
mention_set: WeakEntity<MentionSet>,
+ workspace: WeakEntity<Workspace>,
editor_selections: Vec<(Entity<Buffer>, Range<text::Anchor>)>,
) -> (String, ConfirmCallback) {
const EDITOR_PLACEHOLDER: &str = "selection ";
@@ -2725,6 +2735,7 @@ fn completion_text_for_editor_selections(
let editor = editor.clone();
let selections = selections.clone();
let mention_set = mention_set.clone();
+ let workspace = workspace.clone();
let source_range = source_range.clone();
window.defer(cx, move |window, cx| {
if let Some(editor) = editor.upgrade()
@@ -2736,6 +2747,7 @@ fn completion_text_for_editor_selections(
source_range.clone(),
selections,
editor.clone(),
+ workspace,
window,
cx,
)
@@ -2794,6 +2806,8 @@ fn completion_text_for_terminal_selections(
mention_uri.name().into(),
mention_uri.icon_path(cx),
None,
+ None,
+ None,
range,
editor.downgrade(),
);
diff --git a/crates/agent_ui/src/inline_prompt_editor.rs b/crates/agent_ui/src/inline_prompt_editor.rs
index b5fca12fc58..a541baa7cba 100644
--- a/crates/agent_ui/src/inline_prompt_editor.rs
+++ b/crates/agent_ui/src/inline_prompt_editor.rs
@@ -1615,6 +1615,8 @@ fn insert_message_creases(
crease.label.clone(),
crease.icon_path.clone(),
None,
+ None,
+ None,
start..end,
cx.weak_entity(),
)
diff --git a/crates/agent_ui/src/mention_set.rs b/crates/agent_ui/src/mention_set.rs
index d04f222e186..97d2dfbca6f 100644
--- a/crates/agent_ui/src/mention_set.rs
+++ b/crates/agent_ui/src/mention_set.rs
@@ -520,6 +520,7 @@ impl MentionSet {
source_range: Range<text::Anchor>,
selections: Vec<(Entity<Buffer>, Range<text::Anchor>, Range<usize>)>,
editor: Entity<Editor>,
+ workspace: WeakEntity<Workspace>,
window: &mut Window,
cx: &mut Context<Self>,
) {
@@ -559,6 +560,8 @@ impl MentionSet {
selection_name(abs_path.as_deref(), &line_range).into(),
uri.icon_path(cx),
uri.tooltip_text(),
+ Some(uri.clone()),
+ Some(workspace.clone()),
range,
editor.downgrade(),
);
@@ -1143,11 +1146,20 @@ pub(crate) fn crease_for_mention(
label: SharedString,
icon_path: SharedString,
tooltip: Option<SharedString>,
+ mention_uri: Option<MentionUri>,
+ workspace: Option<WeakEntity<Workspace>>,
range: Range<Anchor>,
editor_entity: WeakEntity<Editor>,
) -> Crease<Anchor> {
let placeholder = FoldPlaceholder {
- render: render_fold_icon_button(icon_path.clone(), label.clone(), tooltip, editor_entity),
+ render: render_fold_icon_button(
+ icon_path.clone(),
+ label.clone(),
+ tooltip,
+ mention_uri,
+ workspace,
+ editor_entity,
+ ),
merge_adjacent: false,
..Default::default()
};
@@ -1162,6 +1174,8 @@ fn render_fold_icon_button(
icon_path: SharedString,
label: SharedString,
tooltip: Option<SharedString>,
+ mention_uri: Option<MentionUri>,
+ workspace: Option<WeakEntity<Workspace>>,
editor: WeakEntity<Editor>,
) -> Arc<dyn Send + Sync + Fn(FoldId, Range<Anchor>, &mut App) -> AnyElement> {
Arc::new({
@@ -1171,6 +1185,8 @@ fn render_fold_icon_button(
.unwrap_or_default();
MentionCrease::new(fold_id, icon_path.clone(), label.clone())
+ .mention_uri(mention_uri.clone())
+ .workspace(workspace.clone())
.is_toggled(is_in_text_selection)
.when_some(tooltip.clone(), |this, tooltip_text| {
this.tooltip(tooltip_text)
diff --git a/crates/agent_ui/src/message_editor.rs b/crates/agent_ui/src/message_editor.rs
index f98625df4b5..61ccdc07f5b 100644
--- a/crates/agent_ui/src/message_editor.rs
+++ b/crates/agent_ui/src/message_editor.rs
@@ -1599,6 +1599,7 @@ impl MessageEditor {
anchor..anchor,
self.editor.downgrade(),
self.mention_set.downgrade(),
+ self.workspace.clone(),
Some(selection),
)
else {