mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-29 02:52:11 +00:00
Migrate expand_glob_import assist to use SyntaxEditor
This commit is contained in:
parent
8d75311400
commit
0e456af6a1
1 changed files with 4 additions and 5 deletions
|
|
@ -9,7 +9,6 @@ use stdx::never;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
AstNode, Direction, SyntaxNode, SyntaxToken, T,
|
AstNode, Direction, SyntaxNode, SyntaxToken, T,
|
||||||
ast::{self, Use, UseTree, VisibilityKind, make},
|
ast::{self, Use, UseTree, VisibilityKind, make},
|
||||||
ted,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -165,8 +164,6 @@ fn build_expanded_import(
|
||||||
let filtered_defs =
|
let filtered_defs =
|
||||||
if reexport_public_items { refs_in_target } else { refs_in_target.used_refs(ctx) };
|
if reexport_public_items { refs_in_target } else { refs_in_target.used_refs(ctx) };
|
||||||
|
|
||||||
let use_tree = builder.make_mut(use_tree);
|
|
||||||
|
|
||||||
let names_to_import = find_names_to_import(filtered_defs, imported_defs);
|
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 expanded = make::use_tree_list(names_to_import.iter().map(|n| {
|
||||||
let path = make::ext::ident_path(
|
let path = make::ext::ident_path(
|
||||||
|
|
@ -176,22 +173,24 @@ fn build_expanded_import(
|
||||||
}))
|
}))
|
||||||
.clone_for_update();
|
.clone_for_update();
|
||||||
|
|
||||||
|
let mut editor = builder.make_editor(use_tree.syntax());
|
||||||
match use_tree.star_token() {
|
match use_tree.star_token() {
|
||||||
Some(star) => {
|
Some(star) => {
|
||||||
let needs_braces = use_tree.path().is_some() && names_to_import.len() != 1;
|
let needs_braces = use_tree.path().is_some() && names_to_import.len() != 1;
|
||||||
if needs_braces {
|
if needs_braces {
|
||||||
ted::replace(star, expanded.syntax())
|
editor.replace(star, expanded.syntax())
|
||||||
} else {
|
} else {
|
||||||
let without_braces = expanded
|
let without_braces = expanded
|
||||||
.syntax()
|
.syntax()
|
||||||
.children_with_tokens()
|
.children_with_tokens()
|
||||||
.filter(|child| !matches!(child.kind(), T!['{'] | T!['}']))
|
.filter(|child| !matches!(child.kind(), T!['{'] | T!['}']))
|
||||||
.collect();
|
.collect();
|
||||||
ted::replace_with_many(star, without_braces)
|
editor.replace_with_many(star, without_braces)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => never!(),
|
None => never!(),
|
||||||
}
|
}
|
||||||
|
builder.add_file_edits(ctx.vfs_file_id(), editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_export_visibility_kind(use_item: &Use) -> VisibilityKind {
|
fn get_export_visibility_kind(use_item: &Use) -> VisibilityKind {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue