Skip to content

Commit 971c393

Browse files
authored
Merge pull request #20305 from Hmikihiro/Migrate_part_of_utils
Migrate part of utils.rs to use SyntaxEditor
2 parents b770720 + 2c16eb8 commit 971c393

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

crates/ide-assists/src/utils.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use syntax::{
2727
make,
2828
syntax_factory::SyntaxFactory,
2929
},
30+
syntax_editor::SyntaxEditor,
3031
ted,
3132
};
3233

@@ -329,7 +330,7 @@ fn invert_special_case(make: &SyntaxFactory, expr: &ast::Expr) -> Option<ast::Ex
329330
fn invert_special_case_legacy(expr: &ast::Expr) -> Option<ast::Expr> {
330331
match expr {
331332
ast::Expr::BinExpr(bin) => {
332-
let bin = bin.clone_for_update();
333+
let bin = bin.clone_subtree();
333334
let op_token = bin.op_token()?;
334335
let rev_token = match op_token.kind() {
335336
T![==] => T![!=],
@@ -345,8 +346,9 @@ fn invert_special_case_legacy(expr: &ast::Expr) -> Option<ast::Expr> {
345346
);
346347
}
347348
};
348-
ted::replace(op_token, make::token(rev_token));
349-
Some(bin.into())
349+
let mut bin_editor = SyntaxEditor::new(bin.syntax().clone());
350+
bin_editor.replace(op_token, make::token(rev_token));
351+
ast::Expr::cast(bin_editor.finish().new_root().clone())
350352
}
351353
ast::Expr::MethodCallExpr(mce) => {
352354
let receiver = mce.receiver()?;

0 commit comments

Comments
 (0)