Skip to content

Commit b118221

Browse files
committed
fix: Map new replacement nodes to their mutable equivalents in SyntaxEditor
1 parent ba56d9b commit b118221

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

crates/ide-assists/src/handlers/reorder_fields.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,9 @@ fn replace<T: AstNode + PartialEq>(
9292
fields: impl Iterator<Item = T>,
9393
sorted_fields: impl IntoIterator<Item = T>,
9494
) {
95-
fields.zip(sorted_fields).for_each(|(field, sorted_field)| {
96-
// FIXME: remove `clone_for_update` when `SyntaxEditor` handles it for us
97-
editor.replace(field.syntax(), sorted_field.syntax().clone_for_update())
98-
});
95+
fields
96+
.zip(sorted_fields)
97+
.for_each(|(field, sorted_field)| editor.replace(field.syntax(), sorted_field.syntax()));
9998
}
10099

101100
fn compute_fields_ranks(

crates/syntax/src/syntax_editor/edit_algo.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ pub(super) fn apply_edits(editor: SyntaxEditor) -> SyntaxEdit {
154154
}
155155
};
156156
}
157+
Change::Replace(SyntaxElement::Node(target), Some(SyntaxElement::Node(new_target))) => {
158+
*target = tree_mutator.make_syntax_mut(target);
159+
if new_target.ancestors().any(|node| node == tree_mutator.immutable) {
160+
*new_target = new_target.clone_for_update();
161+
}
162+
}
157163
Change::Replace(target, _) | Change::ReplaceWithMany(target, _) => {
158164
*target = tree_mutator.make_element_mut(target);
159165
}

0 commit comments

Comments
 (0)