Skip to content

Commit ea413f6

Browse files
authored
Merge pull request #20307 from Hmikihiro/migrate_extract_expression_from_format_string
Migrate `extract_expressions_from_format_string` assist to use `SyntaxEditor`
2 parents b0ae0ab + c9abba3 commit ea413f6

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ use syntax::{
88
AstNode, AstToken, NodeOrToken,
99
SyntaxKind::WHITESPACE,
1010
T,
11-
ast::{self, make},
12-
ted,
11+
ast::{self, make, syntax_factory::SyntaxFactory},
1312
};
1413

1514
// Assist: extract_expressions_from_format_string
@@ -58,8 +57,6 @@ pub(crate) fn extract_expressions_from_format_string(
5857
"Extract format expressions",
5958
tt.syntax().text_range(),
6059
|edit| {
61-
let tt = edit.make_mut(tt);
62-
6360
// Extract existing arguments in macro
6461
let tokens = tt.token_trees_and_tokens().collect_vec();
6562

@@ -131,8 +128,10 @@ pub(crate) fn extract_expressions_from_format_string(
131128
}
132129

133130
// 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());
136135

137136
if let Some(cap) = ctx.config.snippet_cap {
138137
// Add placeholder snippets over placeholder args
@@ -145,15 +144,19 @@ pub(crate) fn extract_expressions_from_format_string(
145144
};
146145

147146
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);
149149
}
150150
}
151151

152152
// Add the final tabstop after the format literal
153153
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);
155156
}
156157
}
158+
editor.add_mappings(make.finish_with_mappings());
159+
edit.add_file_edits(ctx.vfs_file_id(), editor);
157160
},
158161
);
159162

0 commit comments

Comments
 (0)