Skip to content

Commit 2e283c1

Browse files
authored
Merge pull request #20385 from Hmikihiro/migrate_expand_glob_import
Migrate `expand_glob_import` assist to use `SyntaxEditor`
2 parents 6600a1a + 0e456af commit 2e283c1

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use stdx::never;
99
use syntax::{
1010
AstNode, Direction, SyntaxNode, SyntaxToken, T,
1111
ast::{self, Use, UseTree, VisibilityKind, make},
12-
ted,
1312
};
1413

1514
use crate::{
@@ -165,8 +164,6 @@ fn build_expanded_import(
165164
let filtered_defs =
166165
if reexport_public_items { refs_in_target } else { refs_in_target.used_refs(ctx) };
167166

168-
let use_tree = builder.make_mut(use_tree);
169-
170167
let names_to_import = find_names_to_import(filtered_defs, imported_defs);
171168
let expanded = make::use_tree_list(names_to_import.iter().map(|n| {
172169
let path = make::ext::ident_path(
@@ -176,22 +173,24 @@ fn build_expanded_import(
176173
}))
177174
.clone_for_update();
178175

176+
let mut editor = builder.make_editor(use_tree.syntax());
179177
match use_tree.star_token() {
180178
Some(star) => {
181179
let needs_braces = use_tree.path().is_some() && names_to_import.len() != 1;
182180
if needs_braces {
183-
ted::replace(star, expanded.syntax())
181+
editor.replace(star, expanded.syntax())
184182
} else {
185183
let without_braces = expanded
186184
.syntax()
187185
.children_with_tokens()
188186
.filter(|child| !matches!(child.kind(), T!['{'] | T!['}']))
189187
.collect();
190-
ted::replace_with_many(star, without_braces)
188+
editor.replace_with_many(star, without_braces)
191189
}
192190
}
193191
None => never!(),
194192
}
193+
builder.add_file_edits(ctx.vfs_file_id(), editor);
195194
}
196195

197196
fn get_export_visibility_kind(use_item: &Use) -> VisibilityKind {

0 commit comments

Comments
 (0)