@@ -2,7 +2,8 @@ use itertools::Itertools;
2
2
use syntax:: {
3
3
Edition , NodeOrToken , SyntaxElement , T , TextRange , TextSize ,
4
4
ast:: { self , AstNode , AstToken , make} ,
5
- match_ast, ted,
5
+ match_ast,
6
+ syntax_editor:: SyntaxEditor ,
6
7
} ;
7
8
8
9
use crate :: { AssistContext , AssistId , Assists } ;
@@ -178,8 +179,8 @@ fn replace_nested_dbgs(expanded: ast::Expr) -> ast::Expr {
178
179
return replaced;
179
180
}
180
181
181
- let expanded = expanded. clone_for_update ( ) ;
182
-
182
+ let expanded = expanded. clone_subtree ( ) ;
183
+ let mut editor = SyntaxEditor :: new ( expanded . syntax ( ) . clone ( ) ) ;
183
184
// We need to collect to avoid mutation during traversal.
184
185
let macro_exprs: Vec < _ > =
185
186
expanded. syntax ( ) . descendants ( ) . filter_map ( ast:: MacroExpr :: cast) . collect ( ) ;
@@ -191,13 +192,13 @@ fn replace_nested_dbgs(expanded: ast::Expr) -> ast::Expr {
191
192
} ;
192
193
193
194
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 ( ) ) ;
195
196
} else {
196
- ted :: remove ( mac. syntax ( ) ) ;
197
+ editor . delete ( mac. syntax ( ) ) ;
197
198
}
198
199
}
199
-
200
- expanded
200
+ let expanded_syntax = editor . finish ( ) . new_root ( ) . clone ( ) ;
201
+ ast :: Expr :: cast ( expanded_syntax ) . unwrap ( )
201
202
}
202
203
203
204
fn whitespace_start ( it : Option < SyntaxElement > ) -> Option < TextSize > {
0 commit comments