Give unmerge_use a label explaining what it will affect.

This commit is contained in:
Kevin Reid 2023-09-16 12:59:17 -07:00
parent 9d0ccf01a1
commit cac796acb3

View File

@ -36,20 +36,17 @@ pub(crate) fn unmerge_use(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
let old_parent_range = use_.syntax().parent()?.text_range(); let old_parent_range = use_.syntax().parent()?.text_range();
let new_parent = use_.syntax().parent()?; 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(); let target = tree.syntax().text_range();
acc.add( acc.add(AssistId("unmerge_use", AssistKind::RefactorRewrite), label, target, |builder| {
AssistId("unmerge_use", AssistKind::RefactorRewrite),
"Unmerge use",
target,
|builder| {
let new_use = make::use_( let new_use = make::use_(
use_.visibility(), use_.visibility(),
make::use_tree( make::use_tree(path, tree.use_tree_list(), tree.rename(), tree.star_token().is_some()),
path,
tree.use_tree_list(),
tree.rename(),
tree.star_token().is_some(),
),
) )
.clone_for_update(); .clone_for_update();
@ -57,8 +54,7 @@ pub(crate) fn unmerge_use(acc: &mut Assists, ctx: &AssistContext<'_>) -> Option<
ted::insert(Position::after(use_.syntax()), new_use.syntax()); ted::insert(Position::after(use_.syntax()), new_use.syntax());
builder.replace(old_parent_range, new_parent.to_string()); builder.replace(old_parent_range, new_parent.to_string());
}, })
)
} }
fn resolve_full_path(tree: &ast::UseTree) -> Option<ast::Path> { fn resolve_full_path(tree: &ast::UseTree) -> Option<ast::Path> {