mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-30 06:05:19 +00:00
Fix merging of an update of a symbol with an insert_before operation before the same symbol (#19450)
When we insert before some text and then update that same text, we need to preserve and concatenate the new text associated with both operations. Release Notes: - N/A
This commit is contained in:
parent
d209eab058
commit
781fff220c
1 changed files with 85 additions and 2 deletions
|
@ -146,12 +146,28 @@ impl ResolvedEdit {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(description) = &mut self.description {
|
let other_offset_range = other_range.to_offset(buffer);
|
||||||
if let Some(other_description) = &other.description {
|
let offset_range = range.to_offset(buffer);
|
||||||
|
|
||||||
|
// If the other range is empty at the start of this edit's range, combine the new text
|
||||||
|
if other_offset_range.is_empty() && other_offset_range.start == offset_range.start {
|
||||||
|
self.new_text = format!("{}\n{}", other.new_text, self.new_text);
|
||||||
|
self.range.start = other_range.start;
|
||||||
|
|
||||||
|
if let Some((description, other_description)) =
|
||||||
|
self.description.as_mut().zip(other.description.as_ref())
|
||||||
|
{
|
||||||
|
*description = format!("{}\n{}", other_description, description)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if let Some((description, other_description)) =
|
||||||
|
self.description.as_mut().zip(other.description.as_ref())
|
||||||
|
{
|
||||||
description.push('\n');
|
description.push('\n');
|
||||||
description.push_str(other_description);
|
description.push_str(other_description);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -699,6 +715,73 @@ mod tests {
|
||||||
.unindent(),
|
.unindent(),
|
||||||
cx,
|
cx,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Ensure InsertBefore merges correctly with Update of the same text
|
||||||
|
|
||||||
|
assert_edits(
|
||||||
|
"
|
||||||
|
fn foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
"
|
||||||
|
.unindent(),
|
||||||
|
vec![
|
||||||
|
AssistantEditKind::InsertBefore {
|
||||||
|
old_text: "
|
||||||
|
fn foo() {"
|
||||||
|
.unindent(),
|
||||||
|
new_text: "
|
||||||
|
fn bar() {
|
||||||
|
qux();
|
||||||
|
}"
|
||||||
|
.unindent(),
|
||||||
|
description: "implement bar".into(),
|
||||||
|
},
|
||||||
|
AssistantEditKind::Update {
|
||||||
|
old_text: "
|
||||||
|
fn foo() {
|
||||||
|
|
||||||
|
}"
|
||||||
|
.unindent(),
|
||||||
|
new_text: "
|
||||||
|
fn foo() {
|
||||||
|
bar();
|
||||||
|
}"
|
||||||
|
.unindent(),
|
||||||
|
description: "call bar in foo".into(),
|
||||||
|
},
|
||||||
|
AssistantEditKind::InsertAfter {
|
||||||
|
old_text: "
|
||||||
|
fn foo() {
|
||||||
|
|
||||||
|
}
|
||||||
|
"
|
||||||
|
.unindent(),
|
||||||
|
new_text: "
|
||||||
|
fn qux() {
|
||||||
|
// todo
|
||||||
|
}
|
||||||
|
"
|
||||||
|
.unindent(),
|
||||||
|
description: "implement qux".into(),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
"
|
||||||
|
fn bar() {
|
||||||
|
qux();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn qux() {
|
||||||
|
// todo
|
||||||
|
}
|
||||||
|
"
|
||||||
|
.unindent(),
|
||||||
|
cx,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
|
Loading…
Reference in a new issue