diff options
| author | Kevin Reid <kpreid@switchb.org> | 2023-09-16 12:59:17 -0700 |
|---|---|---|
| committer | Kevin Reid <kpreid@switchb.org> | 2023-09-16 13:29:03 -0700 |
| commit | cac796acb30d3af9a2eb9aff02acfae43a6da537 (patch) | |
| tree | 819e6369925fea8dce7dc52593d461e39447b74c | |
| parent | 9d0ccf01a16f4ab72417a804c5a7414f312d95a0 (diff) | |
| download | rust-cac796acb30d3af9a2eb9aff02acfae43a6da537.tar.gz rust-cac796acb30d3af9a2eb9aff02acfae43a6da537.zip | |
Give `unmerge_use` a label explaining what it will affect.
| -rw-r--r-- | crates/ide-assists/src/handlers/unmerge_use.rs | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/crates/ide-assists/src/handlers/unmerge_use.rs b/crates/ide-assists/src/handlers/unmerge_use.rs index dac216b69b7..52df30d9623 100644 --- a/crates/ide-assists/src/handlers/unmerge_use.rs +++ b/crates/ide-assists/src/handlers/unmerge_use.rs @@ -36,29 +36,25 @@ pub(crate) fn unmerge_use(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option< let old_parent_range = use_.syntax().parent()?.text_range(); let new_parent = use_.syntax().parent()?; + // If possible, explain what is going to be done. + let label = match tree.path().and_then(|path| path.first_segment()) { + Some(name) => format!("Unmerge use of `{name}`"), + None => "Unmerge use".into(), + }; + let target = tree.syntax().text_range(); - acc.add( - AssistId("unmerge_use", AssistKind::RefactorRewrite), - "Unmerge use", - target, - |builder| { - let new_use = make::use_( - use_.visibility(), - make::use_tree( - path, - tree.use_tree_list(), - tree.rename(), - tree.star_token().is_some(), - ), - ) - .clone_for_update(); - - tree.remove(); - ted::insert(Position::after(use_.syntax()), new_use.syntax()); - - builder.replace(old_parent_range, new_parent.to_string()); - }, - ) + acc.add(AssistId("unmerge_use", AssistKind::RefactorRewrite), label, target, |builder| { + let new_use = make::use_( + use_.visibility(), + make::use_tree(path, tree.use_tree_list(), tree.rename(), tree.star_token().is_some()), + ) + .clone_for_update(); + + tree.remove(); + ted::insert(Position::after(use_.syntax()), new_use.syntax()); + + builder.replace(old_parent_range, new_parent.to_string()); + }) } fn resolve_full_path(tree: &ast::UseTree) -> Option<ast::Path> { |
