Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions crates/ide-assists/src/handlers/flip_binexpr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,8 @@ pub(crate) fn flip_binexpr(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option
if let FlipAction::FlipAndReplaceOp(binary_op) = action {
editor.replace(op_token, make.token(binary_op))
};
// FIXME: remove `clone_for_update` when `SyntaxEditor` handles it for us
editor.replace(lhs.syntax(), rhs.syntax().clone_for_update());
editor.replace(rhs.syntax(), lhs.syntax().clone_for_update());
editor.replace(lhs.syntax(), rhs.syntax());
editor.replace(rhs.syntax(), lhs.syntax());
editor.add_mappings(make.finish_with_mappings());
builder.add_file_edits(ctx.file_id(), editor);
},
Expand Down
5 changes: 2 additions & 3 deletions crates/ide-assists/src/handlers/flip_comma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,12 @@ pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<(
return None;
}

// FIXME: remove `clone_for_update` when `SyntaxEditor` handles it for us
let prev = match prev {
SyntaxElement::Node(node) => node.clone_for_update().syntax_element(),
SyntaxElement::Node(node) => node.syntax_element(),
_ => prev,
};
let next = match next {
SyntaxElement::Node(node) => node.clone_for_update().syntax_element(),
SyntaxElement::Node(node) => node.syntax_element(),
_ => next,
};

Expand Down
4 changes: 2 additions & 2 deletions crates/ide-assists/src/handlers/flip_trait_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub(crate) fn flip_trait_bound(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
target,
|builder| {
let mut editor = builder.make_editor(parent.syntax());
editor.replace(before.clone(), after.clone_for_update());
editor.replace(after.clone(), before.clone_for_update());
editor.replace(before.clone(), after.clone());
editor.replace(after, before);
builder.add_file_edits(ctx.file_id(), editor);
},
)
Expand Down
7 changes: 3 additions & 4 deletions crates/ide-assists/src/handlers/reorder_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ fn replace<T: AstNode + PartialEq>(
fields: impl Iterator<Item = T>,
sorted_fields: impl IntoIterator<Item = T>,
) {
fields.zip(sorted_fields).for_each(|(field, sorted_field)| {
// FIXME: remove `clone_for_update` when `SyntaxEditor` handles it for us
editor.replace(field.syntax(), sorted_field.syntax().clone_for_update())
});
fields
.zip(sorted_fields)
.for_each(|(field, sorted_field)| editor.replace(field.syntax(), sorted_field.syntax()));
}

fn compute_fields_ranks(
Expand Down
8 changes: 4 additions & 4 deletions crates/ide-assists/src/handlers/reorder_impl_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ pub(crate) fn reorder_impl_items(acc: &mut Assists, ctx: &AssistContext<'_>) ->
|builder| {
let mut editor = builder.make_editor(&parent_node);

assoc_items.into_iter().zip(sorted).for_each(|(old, new)| {
// FIXME: remove `clone_for_update` when `SyntaxEditor` handles it for us
editor.replace(old.syntax(), new.clone_for_update().syntax())
});
assoc_items
.into_iter()
.zip(sorted)
.for_each(|(old, new)| editor.replace(old.syntax(), new.syntax()));

builder.add_file_edits(ctx.file_id(), editor);
},
Expand Down
7 changes: 3 additions & 4 deletions crates/ide-assists/src/handlers/sort_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,9 @@ impl AddRewrite for Assists {
|builder| {
let mut editor = builder.make_editor(target);

old.into_iter().zip(new).for_each(|(old, new)| {
// FIXME: remove `clone_for_update` when `SyntaxEditor` handles it for us
editor.replace(old.syntax(), new.clone_for_update().syntax())
});
old.into_iter()
.zip(new)
.for_each(|(old, new)| editor.replace(old.syntax(), new.syntax()));

builder.add_file_edits(builder.file_id, editor)
},
Expand Down
6 changes: 6 additions & 0 deletions crates/syntax/src/syntax_editor/edit_algo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ pub(super) fn apply_edits(editor: SyntaxEditor) -> SyntaxEdit {
}
};
}
Change::Replace(SyntaxElement::Node(target), Some(SyntaxElement::Node(new_target))) => {
*target = tree_mutator.make_syntax_mut(target);
if new_target.ancestors().any(|node| node == tree_mutator.immutable) {
*new_target = new_target.clone_for_update();
}
}
Change::Replace(target, _) | Change::ReplaceWithMany(target, _) => {
*target = tree_mutator.make_element_mut(target);
}
Expand Down
Loading