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.rs39
1 files changed, 16 insertions, 23 deletions
diff --git a/crates/ide-db/src/imports/insert_use.rs b/crates/ide-db/src/imports/insert_use.rs
index 9318c3e132..fe30a4dc5c 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,
@@ -175,10 +175,9 @@ pub fn insert_use_with_editor(
scope: &ImportScope,
path: ast::Path,
cfg: &InsertUseConfig,
- syntax_editor: &mut SyntaxEditor,
- syntax_factory: &SyntaxFactory,
+ syntax_editor: &SyntaxEditor,
) {
- 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(
@@ -269,9 +268,9 @@ fn insert_use_with_alias_option_with_editor(
path: ast::Path,
cfg: &InsertUseConfig,
alias: Option<ast::Rename>,
- syntax_editor: &mut SyntaxEditor,
- syntax_factory: &SyntaxFactory,
+ syntax_editor: &SyntaxEditor,
) {
+ let make = syntax_editor.make();
let _p = tracing::info_span!("insert_use_with_alias_option").entered();
let mut mb = match cfg.granularity {
ImportGranularity::Crate => Some(MergeBehavior::Crate),
@@ -301,7 +300,7 @@ fn insert_use_with_alias_option_with_editor(
};
}
- let use_tree = syntax_factory.use_tree(path, None, alias, false);
+ let use_tree = 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 +323,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>> {
@@ -604,9 +603,9 @@ fn insert_use_with_editor_(
scope: &ImportScope,
use_item: ast::Use,
group_imports: bool,
- syntax_editor: &mut SyntaxEditor,
- syntax_factory: &SyntaxFactory,
+ syntax_editor: &SyntaxEditor,
) {
+ let make = syntax_editor.make();
let scope_syntax = scope.as_syntax_node();
let insert_use_tree =
use_item.use_tree().expect("`use_item` should have a use tree for `insert_path`");
@@ -656,7 +655,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), make.whitespace("\n"));
}
return;
}
@@ -664,7 +663,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), make.whitespace("\n"));
return;
}
} else {
@@ -703,24 +702,18 @@ 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), 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), 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
+ .insert(Position::first_child_of(scope_syntax), make.whitespace("\n\n"));
syntax_editor.insert(Position::first_child_of(scope_syntax), use_item.syntax());
}
}