Skip to content

Commit 17d028e

Browse files
Merge pull request #22042 from Shourya742/2026-04-14-replace-make-with-syntaxFactory
Replace make with syntax factory in expand_glob_import
2 parents 3c327c7 + b9b09cf commit 17d028e

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use ide_db::{
88
use stdx::never;
99
use syntax::{
1010
AstNode, Direction, SyntaxNode, SyntaxToken, T,
11-
ast::{self, Use, UseTree, VisibilityKind, make},
11+
ast::{self, Use, UseTree, VisibilityKind, syntax_factory::SyntaxFactory},
1212
};
1313

1414
use crate::{
@@ -148,6 +148,8 @@ fn build_expanded_import(
148148
current_module: Module,
149149
reexport_public_items: bool,
150150
) {
151+
let make = SyntaxFactory::with_mappings();
152+
let mut editor = builder.make_editor(use_tree.syntax());
151153
let (must_be_pub, visible_from) = if !reexport_public_items {
152154
(false, current_module)
153155
} else {
@@ -167,15 +169,13 @@ fn build_expanded_import(
167169
if reexport_public_items { refs_in_target } else { refs_in_target.used_refs(ctx) };
168170

169171
let names_to_import = find_names_to_import(filtered_defs, imported_defs);
170-
let expanded = make::use_tree_list(names_to_import.iter().map(|n| {
171-
let path = make::ext::ident_path(
172+
let expanded = make.use_tree_list(names_to_import.iter().map(|n| {
173+
let path = make.ident_path(
172174
&n.display(ctx.db(), current_module.krate(ctx.db()).edition(ctx.db())).to_string(),
173175
);
174-
make::use_tree(path, None, None, false)
175-
}))
176-
.clone_for_update();
176+
make.use_tree(path, None, None, false)
177+
}));
177178

178-
let mut editor = builder.make_editor(use_tree.syntax());
179179
match use_tree.star_token() {
180180
Some(star) => {
181181
let needs_braces = use_tree.path().is_some() && names_to_import.len() != 1;
@@ -192,6 +192,7 @@ fn build_expanded_import(
192192
}
193193
None => never!(),
194194
}
195+
editor.add_mappings(make.finish_with_mappings());
195196
builder.add_file_edits(ctx.vfs_file_id(), editor);
196197
}
197198

crates/syntax/src/ast/syntax_factory/constructors.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,22 @@ impl SyntaxFactory {
7171
make::type_bound_text(bound).clone_for_update()
7272
}
7373

74+
pub fn use_tree_list(
75+
&self,
76+
use_trees: impl IntoIterator<Item = ast::UseTree>,
77+
) -> ast::UseTreeList {
78+
let (use_trees, input) = iterator_input(use_trees);
79+
let ast = make::use_tree_list(use_trees).clone_for_update();
80+
81+
if let Some(mut mapping) = self.mappings() {
82+
let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());
83+
builder.map_children(input, ast.use_trees().map(|b| b.syntax().clone()));
84+
builder.finish(&mut mapping);
85+
}
86+
87+
ast
88+
}
89+
7490
pub fn type_bound_list(
7591
&self,
7692
bounds: impl IntoIterator<Item = ast::TypeBound>,

0 commit comments

Comments
 (0)