Skip to content

Commit b7448a5

Browse files
committed
Migrate remove_dbg assist to use SyntaxEditor
1 parent e9968fc commit b7448a5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use itertools::Itertools;
22
use syntax::{
33
Edition, NodeOrToken, SyntaxElement, T, TextRange, TextSize,
44
ast::{self, AstNode, AstToken, make},
5-
match_ast, ted,
5+
match_ast,
6+
syntax_editor::SyntaxEditor,
67
};
78

89
use crate::{AssistContext, AssistId, Assists};
@@ -178,8 +179,8 @@ fn replace_nested_dbgs(expanded: ast::Expr) -> ast::Expr {
178179
return replaced;
179180
}
180181

181-
let expanded = expanded.clone_for_update();
182-
182+
let expanded = expanded.clone_subtree();
183+
let mut editor = SyntaxEditor::new(expanded.syntax().clone());
183184
// We need to collect to avoid mutation during traversal.
184185
let macro_exprs: Vec<_> =
185186
expanded.syntax().descendants().filter_map(ast::MacroExpr::cast).collect();
@@ -191,13 +192,13 @@ fn replace_nested_dbgs(expanded: ast::Expr) -> ast::Expr {
191192
};
192193

193194
if let Some(expr) = expr_opt {
194-
ted::replace(mac.syntax(), expr.syntax().clone_for_update());
195+
editor.replace(mac.syntax(), expr.syntax().clone_for_update());
195196
} else {
196-
ted::remove(mac.syntax());
197+
editor.delete(mac.syntax());
197198
}
198199
}
199-
200-
expanded
200+
let expanded_syntax = editor.finish().new_root().clone();
201+
ast::Expr::cast(expanded_syntax).unwrap()
201202
}
202203

203204
fn whitespace_start(it: Option<SyntaxElement>) -> Option<TextSize> {

0 commit comments

Comments
 (0)