Skip to content

Commit 19a6543

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

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ fn replace<T: AstNode + PartialEq>(
9393
sorted_fields: impl IntoIterator<Item = T>,
9494
) {
9595
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())
96+
editor.replace(field.syntax(), sorted_field.syntax())
9897
});
9998
}
10099

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)