Skip to content

Commit

Permalink
handle {self} when recursively removing node from UseTree
Browse files Browse the repository at this point in the history
This commits adds logic to `UseTree::remove_recursive` to handle converting
`use x::y::{self};` to `use x::y;` when recurisevly removing nodes. For example
`use x::y::{self, Z};` can become `use x::y` if `Z` is unused.
  • Loading branch information
harrysarson authored and harrysarson-signaloid committed Apr 25, 2024
1 parent 85c120b commit c298bd6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion crates/ide-assists/src/handlers/remove_unused_imports.rs
Expand Up @@ -800,7 +800,7 @@ mod z {
}
mod z {
use super::inner::{self};
use super::inner;
fn f() {
let y = inner::Y();
Expand Down
12 changes: 10 additions & 2 deletions crates/syntax/src/ast/edit_in_place.rs
Expand Up @@ -451,13 +451,21 @@ impl ast::UseTree {
u.remove();
}
} else if let Some(u) = parent.and_then(ast::UseTreeList::cast) {
if u.use_trees().next().is_none() {
if u.is_just_self() {
let parent = u.syntax().parent().and_then(ast::UseTree::cast);
if let Some(u) = parent {
let path = u.path().unwrap();
ted::remove_all_iter(u.syntax().children_with_tokens());
ted::insert_raw(Position::first_child_of(u.syntax()), path.syntax());
}
} else if u.use_trees().next().is_none() {
let parent = u.syntax().parent().and_then(ast::UseTree::cast);
if let Some(u) = parent {
u.remove_recursive();
}
} else {
u.remove_unnecessary_braces();
}
u.remove_unnecessary_braces();
}
}

Expand Down

0 comments on commit c298bd6

Please sign in to comment.