@@ -8,8 +8,7 @@ use syntax::{
8
8
AstNode , AstToken , NodeOrToken ,
9
9
SyntaxKind :: WHITESPACE ,
10
10
T ,
11
- ast:: { self , make} ,
12
- ted,
11
+ ast:: { self , make, syntax_factory:: SyntaxFactory } ,
13
12
} ;
14
13
15
14
// Assist: extract_expressions_from_format_string
@@ -58,8 +57,6 @@ pub(crate) fn extract_expressions_from_format_string(
58
57
"Extract format expressions" ,
59
58
tt. syntax ( ) . text_range ( ) ,
60
59
|edit| {
61
- let tt = edit. make_mut ( tt) ;
62
-
63
60
// Extract existing arguments in macro
64
61
let tokens = tt. token_trees_and_tokens ( ) . collect_vec ( ) ;
65
62
@@ -131,8 +128,10 @@ pub(crate) fn extract_expressions_from_format_string(
131
128
}
132
129
133
130
// Insert new args
134
- let new_tt = make:: token_tree ( tt_delimiter, new_tt_bits) . clone_for_update ( ) ;
135
- ted:: replace ( tt. syntax ( ) , new_tt. syntax ( ) ) ;
131
+ let make = SyntaxFactory :: with_mappings ( ) ;
132
+ let new_tt = make. token_tree ( tt_delimiter, new_tt_bits) ;
133
+ let mut editor = edit. make_editor ( tt. syntax ( ) ) ;
134
+ editor. replace ( tt. syntax ( ) , new_tt. syntax ( ) ) ;
136
135
137
136
if let Some ( cap) = ctx. config . snippet_cap {
138
137
// Add placeholder snippets over placeholder args
@@ -145,15 +144,19 @@ pub(crate) fn extract_expressions_from_format_string(
145
144
} ;
146
145
147
146
if stdx:: always!( placeholder. kind( ) == T ![ _] ) {
148
- edit. add_placeholder_snippet_token ( cap, placeholder) ;
147
+ let annotation = edit. make_placeholder_snippet ( cap) ;
148
+ editor. add_annotation ( placeholder, annotation) ;
149
149
}
150
150
}
151
151
152
152
// Add the final tabstop after the format literal
153
153
if let Some ( NodeOrToken :: Token ( literal) ) = new_tt. token_trees_and_tokens ( ) . nth ( 1 ) {
154
- edit. add_tabstop_after_token ( cap, literal) ;
154
+ let annotation = edit. make_tabstop_after ( cap) ;
155
+ editor. add_annotation ( literal, annotation) ;
155
156
}
156
157
}
158
+ editor. add_mappings ( make. finish_with_mappings ( ) ) ;
159
+ edit. add_file_edits ( ctx. vfs_file_id ( ) , editor) ;
157
160
} ,
158
161
) ;
159
162
0 commit comments