Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-db/src/imports/insert_use.rs')
| -rw-r--r-- | crates/ide-db/src/imports/insert_use.rs | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/crates/ide-db/src/imports/insert_use.rs b/crates/ide-db/src/imports/insert_use.rs index 9318c3e132..d793c2799e 100644 --- a/crates/ide-db/src/imports/insert_use.rs +++ b/crates/ide-db/src/imports/insert_use.rs @@ -9,7 +9,7 @@ use syntax::{ Direction, NodeOrToken, SyntaxKind, SyntaxNode, algo, ast::{ self, AstNode, HasAttrs, HasModuleItem, HasVisibility, PathSegmentKind, - edit_in_place::Removable, make, syntax_factory::SyntaxFactory, + edit_in_place::Removable, make, }, syntax_editor::{Position, SyntaxEditor}, ted, @@ -176,9 +176,8 @@ pub fn insert_use_with_editor( path: ast::Path, cfg: &InsertUseConfig, syntax_editor: &mut SyntaxEditor, - syntax_factory: &SyntaxFactory, ) { - insert_use_with_alias_option_with_editor(scope, path, cfg, None, syntax_editor, syntax_factory); + insert_use_with_alias_option_with_editor(scope, path, cfg, None, syntax_editor); } pub fn insert_use_as_alias( @@ -270,7 +269,6 @@ fn insert_use_with_alias_option_with_editor( cfg: &InsertUseConfig, alias: Option<ast::Rename>, syntax_editor: &mut SyntaxEditor, - syntax_factory: &SyntaxFactory, ) { let _p = tracing::info_span!("insert_use_with_alias_option").entered(); let mut mb = match cfg.granularity { @@ -301,7 +299,7 @@ fn insert_use_with_alias_option_with_editor( }; } - let use_tree = syntax_factory.use_tree(path, None, alias, false); + let use_tree = syntax_editor.make().use_tree(path, None, alias, false); if mb == Some(MergeBehavior::One) && use_tree.path().is_some() { use_tree.wrap_in_tree_list(); } @@ -324,7 +322,7 @@ fn insert_use_with_alias_option_with_editor( } // either we weren't allowed to merge or there is no import that fits the merge conditions // so look for the place we have to insert to - insert_use_with_editor_(scope, use_item, cfg.group, syntax_editor, syntax_factory); + insert_use_with_editor_(scope, use_item, cfg.group, syntax_editor); } pub fn ast_to_remove_for_path_in_use_stmt(path: &ast::Path) -> Option<Box<dyn Removable>> { @@ -605,7 +603,6 @@ fn insert_use_with_editor_( use_item: ast::Use, group_imports: bool, syntax_editor: &mut SyntaxEditor, - syntax_factory: &SyntaxFactory, ) { let scope_syntax = scope.as_syntax_node(); let insert_use_tree = @@ -656,7 +653,7 @@ fn insert_use_with_editor_( cov_mark::hit!(insert_group_new_group); syntax_editor.insert(Position::before(&node), use_item.syntax()); if let Some(node) = algo::non_trivia_sibling(node.into(), Direction::Prev) { - syntax_editor.insert(Position::after(node), syntax_factory.whitespace("\n")); + syntax_editor.insert(Position::after(node), syntax_editor.make().whitespace("\n")); } return; } @@ -664,7 +661,7 @@ fn insert_use_with_editor_( if let Some(node) = last { cov_mark::hit!(insert_group_no_group); syntax_editor.insert(Position::after(&node), use_item.syntax()); - syntax_editor.insert(Position::after(node), syntax_factory.whitespace("\n")); + syntax_editor.insert(Position::after(node), syntax_editor.make().whitespace("\n")); return; } } else { @@ -703,23 +700,20 @@ fn insert_use_with_editor_( { cov_mark::hit!(insert_empty_inner_attr); syntax_editor.insert(Position::after(&last_inner_element), use_item.syntax()); - syntax_editor.insert(Position::after(last_inner_element), syntax_factory.whitespace("\n")); + syntax_editor + .insert(Position::after(last_inner_element), syntax_editor.make().whitespace("\n")); } else { match l_curly { Some(b) => { cov_mark::hit!(insert_empty_module); - syntax_editor.insert(Position::after(&b), syntax_factory.whitespace("\n")); - syntax_editor.insert_with_whitespace( - Position::after(&b), - use_item.syntax(), - syntax_factory, - ); + syntax_editor.insert(Position::after(&b), syntax_editor.make().whitespace("\n")); + syntax_editor.insert_with_whitespace(Position::after(&b), use_item.syntax()); } None => { cov_mark::hit!(insert_empty_file); syntax_editor.insert( Position::first_child_of(scope_syntax), - syntax_factory.whitespace("\n\n"), + syntax_editor.make().whitespace("\n\n"), ); syntax_editor.insert(Position::first_child_of(scope_syntax), use_item.syntax()); } |