Unnamed repository; edit this file 'description' to name the repository.
Merge pull request #22042 from Shourya742/2026-04-14-replace-make-with-syntaxFactory
Replace make with syntax factory in expand_glob_import
Chayim Refael Friedman 5 weeks ago
parent 3c327c7 · parent b9b09cf · commit 17d028e
-rw-r--r--crates/ide-assists/src/handlers/expand_glob_import.rs15
-rw-r--r--crates/syntax/src/ast/syntax_factory/constructors.rs16
2 files changed, 24 insertions, 7 deletions
diff --git a/crates/ide-assists/src/handlers/expand_glob_import.rs b/crates/ide-assists/src/handlers/expand_glob_import.rs
index 6c5c21bfc9..79b9f5d69a 100644
--- a/crates/ide-assists/src/handlers/expand_glob_import.rs
+++ b/crates/ide-assists/src/handlers/expand_glob_import.rs
@@ -8,7 +8,7 @@ use ide_db::{
use stdx::never;
use syntax::{
AstNode, Direction, SyntaxNode, SyntaxToken, T,
- ast::{self, Use, UseTree, VisibilityKind, make},
+ ast::{self, Use, UseTree, VisibilityKind, syntax_factory::SyntaxFactory},
};
use crate::{
@@ -148,6 +148,8 @@ fn build_expanded_import(
current_module: Module,
reexport_public_items: bool,
) {
+ let make = SyntaxFactory::with_mappings();
+ let mut editor = builder.make_editor(use_tree.syntax());
let (must_be_pub, visible_from) = if !reexport_public_items {
(false, current_module)
} else {
@@ -167,15 +169,13 @@ fn build_expanded_import(
if reexport_public_items { refs_in_target } else { refs_in_target.used_refs(ctx) };
let names_to_import = find_names_to_import(filtered_defs, imported_defs);
- let expanded = make::use_tree_list(names_to_import.iter().map(|n| {
- let path = make::ext::ident_path(
+ let expanded = make.use_tree_list(names_to_import.iter().map(|n| {
+ let path = make.ident_path(
&n.display(ctx.db(), current_module.krate(ctx.db()).edition(ctx.db())).to_string(),
);
- make::use_tree(path, None, None, false)
- }))
- .clone_for_update();
+ make.use_tree(path, None, None, false)
+ }));
- let mut editor = builder.make_editor(use_tree.syntax());
match use_tree.star_token() {
Some(star) => {
let needs_braces = use_tree.path().is_some() && names_to_import.len() != 1;
@@ -192,6 +192,7 @@ fn build_expanded_import(
}
None => never!(),
}
+ editor.add_mappings(make.finish_with_mappings());
builder.add_file_edits(ctx.vfs_file_id(), editor);
}
diff --git a/crates/syntax/src/ast/syntax_factory/constructors.rs b/crates/syntax/src/ast/syntax_factory/constructors.rs
index c92f7ec6f3..ad67abfbed 100644
--- a/crates/syntax/src/ast/syntax_factory/constructors.rs
+++ b/crates/syntax/src/ast/syntax_factory/constructors.rs
@@ -71,6 +71,22 @@ impl SyntaxFactory {
make::type_bound_text(bound).clone_for_update()
}
+ pub fn use_tree_list(
+ &self,
+ use_trees: impl IntoIterator<Item = ast::UseTree>,
+ ) -> ast::UseTreeList {
+ let (use_trees, input) = iterator_input(use_trees);
+ let ast = make::use_tree_list(use_trees).clone_for_update();
+
+ if let Some(mut mapping) = self.mappings() {
+ let mut builder = SyntaxMappingBuilder::new(ast.syntax().clone());
+ builder.map_children(input, ast.use_trees().map(|b| b.syntax().clone()));
+ builder.finish(&mut mapping);
+ }
+
+ ast
+ }
+
pub fn type_bound_list(
&self,
bounds: impl IntoIterator<Item = ast::TypeBound>,