Skip to content

Commit d6fef2c

Browse files
committed
Auto merge of #15621 - kpreid:import, r=Veykril
Give `unmerge_use` a label explaining what it will affect. When I'm trying to clean up `use`s, I often feel uncertain about what exactly the effects of choosing an assist will be. This PR makes a small improvement to that by giving “Unmerge use” a label which names the root of the tree that it's going to move, when one exists. There is no test because I didn't see, among the test helpers, a way to assert on the assist label (as opposed to filtering on it). However, I did test the change manually. I looked into making a similar change to “Merge imports”, but that is considerably trickier.
2 parents 4778255 + cac796a commit d6fef2c

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

crates/ide-assists/src/handlers/unmerge_use.rs

+18-22
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,25 @@ pub(crate) fn unmerge_use(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
3636
let old_parent_range = use_.syntax().parent()?.text_range();
3737
let new_parent = use_.syntax().parent()?;
3838

39+
// If possible, explain what is going to be done.
40+
let label = match tree.path().and_then(|path| path.first_segment()) {
41+
Some(name) => format!("Unmerge use of `{name}`"),
42+
None => "Unmerge use".into(),
43+
};
44+
3945
let target = tree.syntax().text_range();
40-
acc.add(
41-
AssistId("unmerge_use", AssistKind::RefactorRewrite),
42-
"Unmerge use",
43-
target,
44-
|builder| {
45-
let new_use = make::use_(
46-
use_.visibility(),
47-
make::use_tree(
48-
path,
49-
tree.use_tree_list(),
50-
tree.rename(),
51-
tree.star_token().is_some(),
52-
),
53-
)
54-
.clone_for_update();
55-
56-
tree.remove();
57-
ted::insert(Position::after(use_.syntax()), new_use.syntax());
58-
59-
builder.replace(old_parent_range, new_parent.to_string());
60-
},
61-
)
46+
acc.add(AssistId("unmerge_use", AssistKind::RefactorRewrite), label, target, |builder| {
47+
let new_use = make::use_(
48+
use_.visibility(),
49+
make::use_tree(path, tree.use_tree_list(), tree.rename(), tree.star_token().is_some()),
50+
)
51+
.clone_for_update();
52+
53+
tree.remove();
54+
ted::insert(Position::after(use_.syntax()), new_use.syntax());
55+
56+
builder.replace(old_parent_range, new_parent.to_string());
57+
})
6258
}
6359

6460
fn resolve_full_path(tree: &ast::UseTree) -> Option<ast::Path> {

0 commit comments

Comments
 (0)