agent: Fix bug where wrong crease for @mention would be displayed (#28558)

Release Notes:

- agent: Fix a bug where an inserted @mention did not show up as the one
that was selected
This commit is contained in:
Bennet Bo Fenner 2025-04-10 20:04:03 -06:00 committed by GitHub
parent c124838a73
commit 5757e352b0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 20 deletions

View file

@ -509,14 +509,13 @@ fn recent_context_picker_entries(
recent recent
} }
pub(crate) fn insert_crease_for_mention( pub(crate) fn insert_fold_for_mention(
excerpt_id: ExcerptId, excerpt_id: ExcerptId,
crease_start: text::Anchor, crease_start: text::Anchor,
content_len: usize, content_len: usize,
crease_label: SharedString, crease_label: SharedString,
crease_icon_path: SharedString, crease_icon_path: SharedString,
editor_entity: Entity<Editor>, editor_entity: Entity<Editor>,
window: &mut Window,
cx: &mut App, cx: &mut App,
) { ) {
editor_entity.update(cx, |editor, cx| { editor_entity.update(cx, |editor, cx| {
@ -535,6 +534,7 @@ pub(crate) fn insert_crease_for_mention(
crease_label, crease_label,
editor_entity.downgrade(), editor_entity.downgrade(),
), ),
merge_adjacent: false,
..Default::default() ..Default::default()
}; };
@ -548,8 +548,9 @@ pub(crate) fn insert_crease_for_mention(
render_trailer, render_trailer,
); );
editor.insert_creases(vec![crease.clone()], cx); editor.display_map.update(cx, |display_map, cx| {
editor.fold_creases(vec![crease], false, window, cx); display_map.fold(vec![crease], cx);
});
}); });
} }

View file

@ -610,21 +610,20 @@ fn confirm_completion_callback(
editor: Entity<Editor>, editor: Entity<Editor>,
add_context_fn: impl Fn(&mut App) -> () + Send + Sync + 'static, add_context_fn: impl Fn(&mut App) -> () + Send + Sync + 'static,
) -> Arc<dyn Fn(CompletionIntent, &mut Window, &mut App) -> bool + Send + Sync> { ) -> Arc<dyn Fn(CompletionIntent, &mut Window, &mut App) -> bool + Send + Sync> {
Arc::new(move |_, window, cx| { Arc::new(move |_, _, cx| {
add_context_fn(cx); add_context_fn(cx);
let crease_text = crease_text.clone(); let crease_text = crease_text.clone();
let crease_icon_path = crease_icon_path.clone(); let crease_icon_path = crease_icon_path.clone();
let editor = editor.clone(); let editor = editor.clone();
window.defer(cx, move |window, cx| { cx.defer(move |cx| {
crate::context_picker::insert_crease_for_mention( crate::context_picker::insert_fold_for_mention(
excerpt_id, excerpt_id,
start, start,
content_len, content_len,
crease_text, crease_text,
crease_icon_path, crease_icon_path,
editor, editor,
window,
cx, cx,
); );
}); });
@ -694,6 +693,7 @@ impl MentionCompletion {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use editor::AnchorRangeExt;
use gpui::{EventEmitter, FocusHandle, Focusable, TestAppContext, VisualTestContext}; use gpui::{EventEmitter, FocusHandle, Focusable, TestAppContext, VisualTestContext};
use project::{Project, ProjectPath}; use project::{Project, ProjectPath};
use serde_json::json; use serde_json::json;
@ -967,7 +967,7 @@ mod tests {
assert_eq!(editor.text(cx), "Lorem [@one.txt](@file:dir/a/one.txt)",); assert_eq!(editor.text(cx), "Lorem [@one.txt](@file:dir/a/one.txt)",);
assert!(!editor.has_visible_completions_menu()); assert!(!editor.has_visible_completions_menu());
assert_eq!( assert_eq!(
crease_ranges(editor, cx), fold_ranges(editor, cx),
vec![Point::new(0, 6)..Point::new(0, 37)] vec![Point::new(0, 6)..Point::new(0, 37)]
); );
}); });
@ -978,7 +978,7 @@ mod tests {
assert_eq!(editor.text(cx), "Lorem [@one.txt](@file:dir/a/one.txt) ",); assert_eq!(editor.text(cx), "Lorem [@one.txt](@file:dir/a/one.txt) ",);
assert!(!editor.has_visible_completions_menu()); assert!(!editor.has_visible_completions_menu());
assert_eq!( assert_eq!(
crease_ranges(editor, cx), fold_ranges(editor, cx),
vec![Point::new(0, 6)..Point::new(0, 37)] vec![Point::new(0, 6)..Point::new(0, 37)]
); );
}); });
@ -992,7 +992,7 @@ mod tests {
); );
assert!(!editor.has_visible_completions_menu()); assert!(!editor.has_visible_completions_menu());
assert_eq!( assert_eq!(
crease_ranges(editor, cx), fold_ranges(editor, cx),
vec![Point::new(0, 6)..Point::new(0, 37)] vec![Point::new(0, 6)..Point::new(0, 37)]
); );
}); });
@ -1006,7 +1006,7 @@ mod tests {
); );
assert!(editor.has_visible_completions_menu()); assert!(editor.has_visible_completions_menu());
assert_eq!( assert_eq!(
crease_ranges(editor, cx), fold_ranges(editor, cx),
vec![Point::new(0, 6)..Point::new(0, 37)] vec![Point::new(0, 6)..Point::new(0, 37)]
); );
}); });
@ -1024,7 +1024,7 @@ mod tests {
); );
assert!(!editor.has_visible_completions_menu()); assert!(!editor.has_visible_completions_menu());
assert_eq!( assert_eq!(
crease_ranges(editor, cx), fold_ranges(editor, cx),
vec![ vec![
Point::new(0, 6)..Point::new(0, 37), Point::new(0, 6)..Point::new(0, 37),
Point::new(0, 44)..Point::new(0, 79) Point::new(0, 44)..Point::new(0, 79)
@ -1041,7 +1041,7 @@ mod tests {
); );
assert!(editor.has_visible_completions_menu()); assert!(editor.has_visible_completions_menu());
assert_eq!( assert_eq!(
crease_ranges(editor, cx), fold_ranges(editor, cx),
vec![ vec![
Point::new(0, 6)..Point::new(0, 37), Point::new(0, 6)..Point::new(0, 37),
Point::new(0, 44)..Point::new(0, 79) Point::new(0, 44)..Point::new(0, 79)
@ -1062,7 +1062,7 @@ mod tests {
); );
assert!(!editor.has_visible_completions_menu()); assert!(!editor.has_visible_completions_menu());
assert_eq!( assert_eq!(
crease_ranges(editor, cx), fold_ranges(editor, cx),
vec![ vec![
Point::new(0, 6)..Point::new(0, 37), Point::new(0, 6)..Point::new(0, 37),
Point::new(0, 44)..Point::new(0, 79), Point::new(0, 44)..Point::new(0, 79),
@ -1072,15 +1072,13 @@ mod tests {
}); });
} }
fn crease_ranges(editor: &Editor, cx: &mut App) -> Vec<Range<Point>> { fn fold_ranges(editor: &Editor, cx: &mut App) -> Vec<Range<Point>> {
let snapshot = editor.buffer().read(cx).snapshot(cx); let snapshot = editor.buffer().read(cx).snapshot(cx);
editor.display_map.update(cx, |display_map, cx| { editor.display_map.update(cx, |display_map, cx| {
display_map display_map
.snapshot(cx) .snapshot(cx)
.crease_snapshot .folds_in_range(0..snapshot.len())
.crease_items_with_offsets(&snapshot) .map(|fold| fold.range.to_point(&snapshot))
.into_iter()
.map(|(_, range)| range)
.collect() .collect()
}) })
} }