Skip to content

Commit 418ad88

Browse files
committed
feat: Migrate flip_trait_bound assist to SyntaxEditor
1 parent ff6b020 commit 418ad88

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/handlers/flip_trait_bound.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,23 @@ pub(crate) fn flip_trait_bound(acc: &mut Assists, ctx: &AssistContext<'_>) -> Op
2323
let plus = ctx.find_token_syntax_at_offset(T![+])?;
2424

2525
// Make sure we're in a `TypeBoundList`
26-
ast::TypeBoundList::cast(plus.parent()?)?;
26+
let parent = ast::TypeBoundList::cast(plus.parent()?)?;
2727

2828
let (before, after) = (
29-
non_trivia_sibling(plus.clone().into(), Direction::Prev)?,
30-
non_trivia_sibling(plus.clone().into(), Direction::Next)?,
29+
non_trivia_sibling(plus.clone().into(), Direction::Prev)?.into_node()?,
30+
non_trivia_sibling(plus.clone().into(), Direction::Next)?.into_node()?,
3131
);
3232

3333
let target = plus.text_range();
3434
acc.add(
3535
AssistId("flip_trait_bound", AssistKind::RefactorRewrite),
3636
"Flip trait bounds",
3737
target,
38-
|edit| {
39-
edit.replace(before.text_range(), after.to_string());
40-
edit.replace(after.text_range(), before.to_string());
38+
|builder| {
39+
let mut editor = builder.make_editor(parent.syntax());
40+
editor.replace(before.clone(), after.clone_for_update());
41+
editor.replace(after.clone(), before.clone_for_update());
42+
builder.add_file_edits(ctx.file_id(), editor);
4143
},
4244
)
4345
}

0 commit comments

Comments
 (0)