From 36cc81ac71e4246bf58a3758735cc68f7adb5e0f Mon Sep 17 00:00:00 2001 From: kjeremy Date: Thu, 2 Jul 2020 17:48:35 -0400 Subject: Move AssistKind into AssistId --- crates/ra_assists/src/handlers/add_custom_impl.rs | 2 +- crates/ra_assists/src/handlers/add_derive.rs | 2 +- .../ra_assists/src/handlers/add_explicit_type.rs | 3 +- .../src/handlers/add_from_impl_for_enum.rs | 3 +- crates/ra_assists/src/handlers/add_function.rs | 3 +- crates/ra_assists/src/handlers/add_impl.rs | 3 +- .../src/handlers/add_missing_impl_members.rs | 2 +- crates/ra_assists/src/handlers/add_new.rs | 3 +- crates/ra_assists/src/handlers/add_turbo_fish.rs | 3 +- crates/ra_assists/src/handlers/apply_demorgan.rs | 3 +- crates/ra_assists/src/handlers/auto_import.rs | 3 +- .../src/handlers/change_return_type_to_result.rs | 3 +- .../ra_assists/src/handlers/change_visibility.rs | 9 +-- crates/ra_assists/src/handlers/early_return.rs | 3 +- .../handlers/extract_struct_from_enum_variant.rs | 3 +- crates/ra_assists/src/handlers/extract_variable.rs | 3 +- crates/ra_assists/src/handlers/fill_match_arms.rs | 3 +- crates/ra_assists/src/handlers/fix_visibility.rs | 4 +- crates/ra_assists/src/handlers/flip_binexpr.rs | 3 +- crates/ra_assists/src/handlers/flip_comma.rs | 3 +- crates/ra_assists/src/handlers/flip_trait_bound.rs | 3 +- .../src/handlers/inline_local_variable.rs | 3 +- .../src/handlers/introduce_named_lifetime.rs | 4 +- crates/ra_assists/src/handlers/invert_if.rs | 2 +- crates/ra_assists/src/handlers/merge_imports.rs | 3 +- crates/ra_assists/src/handlers/merge_match_arms.rs | 3 +- crates/ra_assists/src/handlers/move_bounds.rs | 3 +- crates/ra_assists/src/handlers/move_guard.rs | 6 +- crates/ra_assists/src/handlers/raw_string.rs | 11 ++-- crates/ra_assists/src/handlers/remove_dbg.rs | 2 +- crates/ra_assists/src/handlers/remove_mut.rs | 3 +- crates/ra_assists/src/handlers/reorder_fields.rs | 3 +- .../src/handlers/replace_if_let_with_match.rs | 3 +- .../src/handlers/replace_let_with_if_let.rs | 3 +- .../handlers/replace_qualified_name_with_use.rs | 3 +- .../src/handlers/replace_unwrap_with_match.rs | 3 +- crates/ra_assists/src/handlers/split_import.rs | 2 +- crates/ra_assists/src/handlers/unwrap_block.rs | 66 +++++++++------------- 38 files changed, 72 insertions(+), 118 deletions(-) (limited to 'crates/ra_assists/src/handlers') diff --git a/crates/ra_assists/src/handlers/add_custom_impl.rs b/crates/ra_assists/src/handlers/add_custom_impl.rs index e86b01dbb..acb07e36a 100644 --- a/crates/ra_assists/src/handlers/add_custom_impl.rs +++ b/crates/ra_assists/src/handlers/add_custom_impl.rs @@ -52,7 +52,7 @@ pub(crate) fn add_custom_impl(acc: &mut Assists, ctx: &AssistContext) -> Option< format!("Add custom impl `{}` for `{}`", trait_token.text().as_str(), annotated_name); let target = attr.syntax().text_range(); - acc.add(AssistId("add_custom_impl"), AssistKind::Refactor, label, target, |builder| { + acc.add(AssistId("add_custom_impl", AssistKind::Refactor), label, target, |builder| { let new_attr_input = input .syntax() .descendants_with_tokens() diff --git a/crates/ra_assists/src/handlers/add_derive.rs b/crates/ra_assists/src/handlers/add_derive.rs index 3b7a570b0..12acfbbe4 100644 --- a/crates/ra_assists/src/handlers/add_derive.rs +++ b/crates/ra_assists/src/handlers/add_derive.rs @@ -29,7 +29,7 @@ pub(crate) fn add_derive(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let nominal = ctx.find_node_at_offset::()?; let node_start = derive_insertion_offset(&nominal)?; let target = nominal.syntax().text_range(); - acc.add(AssistId("add_derive"), AssistKind::Refactor, "Add `#[derive]`", target, |builder| { + acc.add(AssistId("add_derive", AssistKind::Refactor), "Add `#[derive]`", target, |builder| { let derive_attr = nominal .attrs() .filter_map(|x| x.as_simple_call()) diff --git a/crates/ra_assists/src/handlers/add_explicit_type.rs b/crates/ra_assists/src/handlers/add_explicit_type.rs index 653137d43..39a5321d1 100644 --- a/crates/ra_assists/src/handlers/add_explicit_type.rs +++ b/crates/ra_assists/src/handlers/add_explicit_type.rs @@ -59,8 +59,7 @@ pub(crate) fn add_explicit_type(acc: &mut Assists, ctx: &AssistContext) -> Optio let inferred_type = ty.display_source_code(ctx.db(), module.into()).ok()?; acc.add( - AssistId("add_explicit_type"), - AssistKind::RefactorRewrite, + AssistId("add_explicit_type", AssistKind::RefactorRewrite), format!("Insert explicit type `{}`", inferred_type), pat_range, |builder| match ascribed_ty { diff --git a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs index 505085c54..a324670ed 100644 --- a/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs +++ b/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs @@ -45,8 +45,7 @@ pub(crate) fn add_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext) -> let target = variant.syntax().text_range(); acc.add( - AssistId("add_from_impl_for_enum"), - AssistKind::Refactor, + AssistId("add_from_impl_for_enum", AssistKind::Refactor), "Add From impl for this enum variant", target, |edit| { diff --git a/crates/ra_assists/src/handlers/add_function.rs b/crates/ra_assists/src/handlers/add_function.rs index a11bc2551..6f2950daf 100644 --- a/crates/ra_assists/src/handlers/add_function.rs +++ b/crates/ra_assists/src/handlers/add_function.rs @@ -63,8 +63,7 @@ pub(crate) fn add_function(acc: &mut Assists, ctx: &AssistContext) -> Option<()> let target = call.syntax().text_range(); acc.add( - AssistId("add_function"), - AssistKind::RefactorExtract, + AssistId("add_function", AssistKind::RefactorExtract), "Add function", target, |builder| { diff --git a/crates/ra_assists/src/handlers/add_impl.rs b/crates/ra_assists/src/handlers/add_impl.rs index 405e3c568..2f603ef9c 100644 --- a/crates/ra_assists/src/handlers/add_impl.rs +++ b/crates/ra_assists/src/handlers/add_impl.rs @@ -27,8 +27,7 @@ pub(crate) fn add_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let name = nominal.name()?; let target = nominal.syntax().text_range(); acc.add( - AssistId("add_impl"), - AssistKind::Refactor, + AssistId("add_impl", AssistKind::Refactor), format!("Implement {}", name.text().as_str()), target, |edit| { diff --git a/crates/ra_assists/src/handlers/add_missing_impl_members.rs b/crates/ra_assists/src/handlers/add_missing_impl_members.rs index 13b441a29..d6aaf53f1 100644 --- a/crates/ra_assists/src/handlers/add_missing_impl_members.rs +++ b/crates/ra_assists/src/handlers/add_missing_impl_members.rs @@ -147,7 +147,7 @@ fn add_missing_impl_members_inner( } let target = impl_def.syntax().text_range(); - acc.add(AssistId(assist_id), AssistKind::QuickFix, label, target, |builder| { + acc.add(AssistId(assist_id, AssistKind::QuickFix), label, target, |builder| { let n_existing_items = impl_item_list.assoc_items().count(); let source_scope = ctx.sema.scope_for_def(trait_); let target_scope = ctx.sema.scope(impl_item_list.syntax()); diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index 4cd3ca264..84eda5486 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs @@ -43,8 +43,7 @@ pub(crate) fn add_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let target = strukt.syntax().text_range(); acc.add( - AssistId("add_new"), - AssistKind::Refactor, + AssistId("add_new", AssistKind::Refactor), "Add default constructor", target, |builder| { diff --git a/crates/ra_assists/src/handlers/add_turbo_fish.rs b/crates/ra_assists/src/handlers/add_turbo_fish.rs index 7a807fbde..f7e1a7b05 100644 --- a/crates/ra_assists/src/handlers/add_turbo_fish.rs +++ b/crates/ra_assists/src/handlers/add_turbo_fish.rs @@ -46,8 +46,7 @@ pub(crate) fn add_turbo_fish(acc: &mut Assists, ctx: &AssistContext) -> Option<( return None; } acc.add( - AssistId("add_turbo_fish"), - AssistKind::RefactorRewrite, + AssistId("add_turbo_fish", AssistKind::RefactorRewrite), "Add `::<>`", ident.text_range(), |builder| match ctx.config.snippet_cap { diff --git a/crates/ra_assists/src/handlers/apply_demorgan.rs b/crates/ra_assists/src/handlers/apply_demorgan.rs index a1fd6e112..de701f8b8 100644 --- a/crates/ra_assists/src/handlers/apply_demorgan.rs +++ b/crates/ra_assists/src/handlers/apply_demorgan.rs @@ -40,8 +40,7 @@ pub(crate) fn apply_demorgan(acc: &mut Assists, ctx: &AssistContext) -> Option<( let not_rhs = invert_boolean_expression(rhs); acc.add( - AssistId("apply_demorgan"), - AssistKind::RefactorRewrite, + AssistId("apply_demorgan", AssistKind::RefactorRewrite), "Apply De Morgan's law", op_range, |edit| { diff --git a/crates/ra_assists/src/handlers/auto_import.rs b/crates/ra_assists/src/handlers/auto_import.rs index 4d97ed101..947be3b9b 100644 --- a/crates/ra_assists/src/handlers/auto_import.rs +++ b/crates/ra_assists/src/handlers/auto_import.rs @@ -48,8 +48,7 @@ pub(crate) fn auto_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> for import in proposed_imports { acc.add_group( &group, - AssistId("auto_import"), - AssistKind::QuickFix, + AssistId("auto_import", AssistKind::QuickFix), format!("Import `{}`", &import), range, |builder| { diff --git a/crates/ra_assists/src/handlers/change_return_type_to_result.rs b/crates/ra_assists/src/handlers/change_return_type_to_result.rs index 2be6d5e49..24e5f6963 100644 --- a/crates/ra_assists/src/handlers/change_return_type_to_result.rs +++ b/crates/ra_assists/src/handlers/change_return_type_to_result.rs @@ -35,8 +35,7 @@ pub(crate) fn change_return_type_to_result(acc: &mut Assists, ctx: &AssistContex let block_expr = &fn_def.body()?; acc.add( - AssistId("change_return_type_to_result"), - AssistKind::RefactorRewrite, + AssistId("change_return_type_to_result", AssistKind::RefactorRewrite), "Change return type to Result", type_ref.syntax().text_range(), |builder| { diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs index 34c7e481d..703ee2143 100644 --- a/crates/ra_assists/src/handlers/change_visibility.rs +++ b/crates/ra_assists/src/handlers/change_visibility.rs @@ -63,8 +63,7 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { }; acc.add( - AssistId("change_visibility"), - AssistKind::RefactorRewrite, + AssistId("change_visibility", AssistKind::RefactorRewrite), "Change visibility to pub(crate)", target, |edit| { @@ -77,8 +76,7 @@ fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> { if vis.syntax().text() == "pub" { let target = vis.syntax().text_range(); return acc.add( - AssistId("change_visibility"), - AssistKind::RefactorRewrite, + AssistId("change_visibility", AssistKind::RefactorRewrite), "Change Visibility to pub(crate)", target, |edit| { @@ -89,8 +87,7 @@ fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> { if vis.syntax().text() == "pub(crate)" { let target = vis.syntax().text_range(); return acc.add( - AssistId("change_visibility"), - AssistKind::RefactorRewrite, + AssistId("change_visibility", AssistKind::RefactorRewrite), "Change visibility to pub", target, |edit| { diff --git a/crates/ra_assists/src/handlers/early_return.rs b/crates/ra_assists/src/handlers/early_return.rs index 9ccd42cd7..330459f3c 100644 --- a/crates/ra_assists/src/handlers/early_return.rs +++ b/crates/ra_assists/src/handlers/early_return.rs @@ -100,8 +100,7 @@ pub(crate) fn convert_to_guarded_return(acc: &mut Assists, ctx: &AssistContext) let target = if_expr.syntax().text_range(); acc.add( - AssistId("convert_to_guarded_return"), - AssistKind::RefactorRewrite, + AssistId("convert_to_guarded_return", AssistKind::RefactorRewrite), "Convert to guarded return", target, |edit| { diff --git a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs index e1ae485c9..2b8e273b3 100644 --- a/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs +++ b/crates/ra_assists/src/handlers/extract_struct_from_enum_variant.rs @@ -49,8 +49,7 @@ pub(crate) fn extract_struct_from_enum_variant( let current_module = enum_hir.module(ctx.db()); let target = variant.syntax().text_range(); acc.add( - AssistId("extract_struct_from_enum_variant"), - AssistKind::RefactorRewrite, + AssistId("extract_struct_from_enum_variant", AssistKind::RefactorRewrite), "Extract struct from enum variant", target, |builder| { diff --git a/crates/ra_assists/src/handlers/extract_variable.rs b/crates/ra_assists/src/handlers/extract_variable.rs index 8f7ffdaff..481baf1a4 100644 --- a/crates/ra_assists/src/handlers/extract_variable.rs +++ b/crates/ra_assists/src/handlers/extract_variable.rs @@ -44,8 +44,7 @@ pub(crate) fn extract_variable(acc: &mut Assists, ctx: &AssistContext) -> Option } let target = expr.syntax().text_range(); acc.add( - AssistId("extract_variable"), - AssistKind::RefactorExtract, + AssistId("extract_variable", AssistKind::RefactorExtract), "Extract into variable", target, move |edit| { diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs index c779e749b..511355e07 100644 --- a/crates/ra_assists/src/handlers/fill_match_arms.rs +++ b/crates/ra_assists/src/handlers/fill_match_arms.rs @@ -104,8 +104,7 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option< let target = match_expr.syntax().text_range(); acc.add( - AssistId("fill_match_arms"), - AssistKind::QuickFix, + AssistId("fill_match_arms", AssistKind::QuickFix), "Fill match arms", target, |builder| { diff --git a/crates/ra_assists/src/handlers/fix_visibility.rs b/crates/ra_assists/src/handlers/fix_visibility.rs index 9c6f9efc2..e212557c8 100644 --- a/crates/ra_assists/src/handlers/fix_visibility.rs +++ b/crates/ra_assists/src/handlers/fix_visibility.rs @@ -58,7 +58,7 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext) -> O Some(name) => format!("Change visibility of {} to {}", name, missing_visibility), }; - acc.add(AssistId("fix_visibility"), AssistKind::QuickFix, assist_label, target, |builder| { + acc.add(AssistId("fix_visibility", AssistKind::QuickFix), assist_label, target, |builder| { builder.edit_file(target_file); match ctx.config.snippet_cap { Some(cap) => builder.insert_snippet(cap, offset, format!("$0{} ", missing_visibility)), @@ -101,7 +101,7 @@ fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext) -> let assist_label = format!("Change visibility of {}.{} to {}", parent_name, target_name, missing_visibility); - acc.add(AssistId("fix_visibility"), AssistKind::QuickFix, assist_label, target, |builder| { + acc.add(AssistId("fix_visibility", AssistKind::QuickFix), assist_label, target, |builder| { builder.edit_file(target_file); match ctx.config.snippet_cap { Some(cap) => builder.insert_snippet(cap, offset, format!("$0{} ", missing_visibility)), diff --git a/crates/ra_assists/src/handlers/flip_binexpr.rs b/crates/ra_assists/src/handlers/flip_binexpr.rs index aee55762f..3cd532650 100644 --- a/crates/ra_assists/src/handlers/flip_binexpr.rs +++ b/crates/ra_assists/src/handlers/flip_binexpr.rs @@ -34,8 +34,7 @@ pub(crate) fn flip_binexpr(acc: &mut Assists, ctx: &AssistContext) -> Option<()> } acc.add( - AssistId("flip_binexpr"), - AssistKind::RefactorRewrite, + AssistId("flip_binexpr", AssistKind::RefactorRewrite), "Flip binary expression", op_range, |edit| { diff --git a/crates/ra_assists/src/handlers/flip_comma.rs b/crates/ra_assists/src/handlers/flip_comma.rs index 9971ffa71..55a971dc7 100644 --- a/crates/ra_assists/src/handlers/flip_comma.rs +++ b/crates/ra_assists/src/handlers/flip_comma.rs @@ -29,8 +29,7 @@ pub(crate) fn flip_comma(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { } acc.add( - AssistId("flip_comma"), - AssistKind::RefactorRewrite, + AssistId("flip_comma", AssistKind::RefactorRewrite), "Flip comma", comma.text_range(), |edit| { diff --git a/crates/ra_assists/src/handlers/flip_trait_bound.rs b/crates/ra_assists/src/handlers/flip_trait_bound.rs index 192f70ccb..1234f4d29 100644 --- a/crates/ra_assists/src/handlers/flip_trait_bound.rs +++ b/crates/ra_assists/src/handlers/flip_trait_bound.rs @@ -34,8 +34,7 @@ pub(crate) fn flip_trait_bound(acc: &mut Assists, ctx: &AssistContext) -> Option let target = plus.text_range(); acc.add( - AssistId("flip_trait_bound"), - AssistKind::RefactorRewrite, + AssistId("flip_trait_bound", AssistKind::RefactorRewrite), "Flip trait bounds", target, |edit| { diff --git a/crates/ra_assists/src/handlers/inline_local_variable.rs b/crates/ra_assists/src/handlers/inline_local_variable.rs index f1bd8b46d..2fdfabaf5 100644 --- a/crates/ra_assists/src/handlers/inline_local_variable.rs +++ b/crates/ra_assists/src/handlers/inline_local_variable.rs @@ -111,8 +111,7 @@ pub(crate) fn inline_local_variable(acc: &mut Assists, ctx: &AssistContext) -> O let target = bind_pat.syntax().text_range(); acc.add( - AssistId("inline_local_variable"), - AssistKind::RefactorInline, + AssistId("inline_local_variable", AssistKind::RefactorInline), "Inline variable", target, move |builder| { diff --git a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs index 374274824..967593031 100644 --- a/crates/ra_assists/src/handlers/introduce_named_lifetime.rs +++ b/crates/ra_assists/src/handlers/introduce_named_lifetime.rs @@ -83,7 +83,7 @@ fn generate_fn_def_assist( _ => return None, } }; - acc.add(AssistId(ASSIST_NAME), AssistKind::Refactor, ASSIST_LABEL, lifetime_loc, |builder| { + acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| { add_lifetime_param(fn_def, builder, end_of_fn_ident, new_lifetime_param); builder.replace(lifetime_loc, format!("'{}", new_lifetime_param)); loc_needing_lifetime.map(|loc| builder.insert(loc, format!("'{} ", new_lifetime_param))); @@ -98,7 +98,7 @@ fn generate_impl_def_assist( ) -> Option<()> { let new_lifetime_param = generate_unique_lifetime_param_name(&impl_def.type_param_list())?; let end_of_impl_kw = impl_def.impl_token()?.text_range().end(); - acc.add(AssistId(ASSIST_NAME), AssistKind::Refactor, ASSIST_LABEL, lifetime_loc, |builder| { + acc.add(AssistId(ASSIST_NAME, AssistKind::Refactor), ASSIST_LABEL, lifetime_loc, |builder| { add_lifetime_param(impl_def, builder, end_of_impl_kw, new_lifetime_param); builder.replace(lifetime_loc, format!("'{}", new_lifetime_param)); }) diff --git a/crates/ra_assists/src/handlers/invert_if.rs b/crates/ra_assists/src/handlers/invert_if.rs index eebb2364d..bbe3f3643 100644 --- a/crates/ra_assists/src/handlers/invert_if.rs +++ b/crates/ra_assists/src/handlers/invert_if.rs @@ -54,7 +54,7 @@ pub(crate) fn invert_if(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let else_node = else_block.syntax(); let else_range = else_node.text_range(); let then_range = then_node.text_range(); - acc.add(AssistId("invert_if"), AssistKind::RefactorRewrite, "Invert if", if_range, |edit| { + acc.add(AssistId("invert_if", AssistKind::RefactorRewrite), "Invert if", if_range, |edit| { edit.replace(cond_range, flip_cond.syntax().text()); edit.replace(else_range, then_node.text()); edit.replace(then_range, else_node.text()); diff --git a/crates/ra_assists/src/handlers/merge_imports.rs b/crates/ra_assists/src/handlers/merge_imports.rs index b0458e17f..1beccb61c 100644 --- a/crates/ra_assists/src/handlers/merge_imports.rs +++ b/crates/ra_assists/src/handlers/merge_imports.rs @@ -57,8 +57,7 @@ pub(crate) fn merge_imports(acc: &mut Assists, ctx: &AssistContext) -> Option<() let target = tree.syntax().text_range(); acc.add( - AssistId("merge_imports"), - AssistKind::RefactorRewrite, + AssistId("merge_imports", AssistKind::RefactorRewrite), "Merge imports", target, |builder| { diff --git a/crates/ra_assists/src/handlers/merge_match_arms.rs b/crates/ra_assists/src/handlers/merge_match_arms.rs index f0f11a046..186a1f618 100644 --- a/crates/ra_assists/src/handlers/merge_match_arms.rs +++ b/crates/ra_assists/src/handlers/merge_match_arms.rs @@ -60,8 +60,7 @@ pub(crate) fn merge_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option } acc.add( - AssistId("merge_match_arms"), - AssistKind::RefactorRewrite, + AssistId("merge_match_arms", AssistKind::RefactorRewrite), "Merge match arms", current_text_range, |edit| { diff --git a/crates/ra_assists/src/handlers/move_bounds.rs b/crates/ra_assists/src/handlers/move_bounds.rs index bcedd39a8..ba3dafb99 100644 --- a/crates/ra_assists/src/handlers/move_bounds.rs +++ b/crates/ra_assists/src/handlers/move_bounds.rs @@ -51,8 +51,7 @@ pub(crate) fn move_bounds_to_where_clause(acc: &mut Assists, ctx: &AssistContext let target = type_param_list.syntax().text_range(); acc.add( - AssistId("move_bounds_to_where_clause"), - AssistKind::RefactorRewrite, + AssistId("move_bounds_to_where_clause", AssistKind::RefactorRewrite), "Move to where clause", target, |edit| { diff --git a/crates/ra_assists/src/handlers/move_guard.rs b/crates/ra_assists/src/handlers/move_guard.rs index 77c1b66be..4060d34c6 100644 --- a/crates/ra_assists/src/handlers/move_guard.rs +++ b/crates/ra_assists/src/handlers/move_guard.rs @@ -41,8 +41,7 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext) -> let target = guard.syntax().text_range(); acc.add( - AssistId("move_guard_to_arm_body"), - AssistKind::RefactorRewrite, + AssistId("move_guard_to_arm_body", AssistKind::RefactorRewrite), "Move guard to arm body", target, |edit| { @@ -106,8 +105,7 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex let target = if_expr.syntax().text_range(); acc.add( - AssistId("move_arm_cond_to_match_guard"), - AssistKind::RefactorRewrite, + AssistId("move_arm_cond_to_match_guard", AssistKind::RefactorRewrite), "Move condition to match guard", target, |edit| { diff --git a/crates/ra_assists/src/handlers/raw_string.rs b/crates/ra_assists/src/handlers/raw_string.rs index 8d0dac528..96679e160 100644 --- a/crates/ra_assists/src/handlers/raw_string.rs +++ b/crates/ra_assists/src/handlers/raw_string.rs @@ -27,8 +27,7 @@ pub(crate) fn make_raw_string(acc: &mut Assists, ctx: &AssistContext) -> Option< let value = token.value()?; let target = token.syntax().text_range(); acc.add( - AssistId("make_raw_string"), - AssistKind::RefactorRewrite, + AssistId("make_raw_string", AssistKind::RefactorRewrite), "Rewrite as raw string", target, |edit| { @@ -65,8 +64,7 @@ pub(crate) fn make_usual_string(acc: &mut Assists, ctx: &AssistContext) -> Optio let value = token.value()?; let target = token.syntax().text_range(); acc.add( - AssistId("make_usual_string"), - AssistKind::RefactorRewrite, + AssistId("make_usual_string", AssistKind::RefactorRewrite), "Rewrite as regular string", target, |edit| { @@ -95,7 +93,7 @@ pub(crate) fn make_usual_string(acc: &mut Assists, ctx: &AssistContext) -> Optio pub(crate) fn add_hash(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let token = ctx.find_token_at_offset(RAW_STRING)?; let target = token.text_range(); - acc.add(AssistId("add_hash"), AssistKind::Refactor, "Add # to raw string", target, |edit| { + acc.add(AssistId("add_hash", AssistKind::Refactor), "Add # to raw string", target, |edit| { edit.insert(token.text_range().start() + TextSize::of('r'), "#"); edit.insert(token.text_range().end(), "#"); }) @@ -125,8 +123,7 @@ pub(crate) fn remove_hash(acc: &mut Assists, ctx: &AssistContext) -> Option<()> } let target = token.text_range(); acc.add( - AssistId("remove_hash"), - AssistKind::RefactorRewrite, + AssistId("remove_hash", AssistKind::RefactorRewrite), "Remove hash from raw string", target, |edit| { diff --git a/crates/ra_assists/src/handlers/remove_dbg.rs b/crates/ra_assists/src/handlers/remove_dbg.rs index e5571676f..a616cca57 100644 --- a/crates/ra_assists/src/handlers/remove_dbg.rs +++ b/crates/ra_assists/src/handlers/remove_dbg.rs @@ -38,7 +38,7 @@ pub(crate) fn remove_dbg(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { }; let target = macro_call.syntax().text_range(); - acc.add(AssistId("remove_dbg"), AssistKind::Refactor, "Remove dbg!()", target, |builder| { + acc.add(AssistId("remove_dbg", AssistKind::Refactor), "Remove dbg!()", target, |builder| { builder.replace(macro_range, macro_content); }) } diff --git a/crates/ra_assists/src/handlers/remove_mut.rs b/crates/ra_assists/src/handlers/remove_mut.rs index a8173694a..ef55c354e 100644 --- a/crates/ra_assists/src/handlers/remove_mut.rs +++ b/crates/ra_assists/src/handlers/remove_mut.rs @@ -27,8 +27,7 @@ pub(crate) fn remove_mut(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let target = mut_token.text_range(); acc.add( - AssistId("remove_mut"), - AssistKind::Refactor, + AssistId("remove_mut", AssistKind::Refactor), "Remove `mut` keyword", target, |builder| { diff --git a/crates/ra_assists/src/handlers/reorder_fields.rs b/crates/ra_assists/src/handlers/reorder_fields.rs index 4a542a5d7..2ac1c56cf 100644 --- a/crates/ra_assists/src/handlers/reorder_fields.rs +++ b/crates/ra_assists/src/handlers/reorder_fields.rs @@ -43,8 +43,7 @@ fn reorder(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { let target = record.syntax().text_range(); acc.add( - AssistId("reorder_fields"), - AssistKind::RefactorRewrite, + AssistId("reorder_fields", AssistKind::RefactorRewrite), "Reorder record fields", target, |edit| { diff --git a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs index 9ef121a4c..b7e30a7f2 100644 --- a/crates/ra_assists/src/handlers/replace_if_let_with_match.rs +++ b/crates/ra_assists/src/handlers/replace_if_let_with_match.rs @@ -49,8 +49,7 @@ pub(crate) fn replace_if_let_with_match(acc: &mut Assists, ctx: &AssistContext) let target = if_expr.syntax().text_range(); acc.add( - AssistId("replace_if_let_with_match"), - AssistKind::RefactorRewrite, + AssistId("replace_if_let_with_match", AssistKind::RefactorRewrite), "Replace with match", target, move |edit| { diff --git a/crates/ra_assists/src/handlers/replace_let_with_if_let.rs b/crates/ra_assists/src/handlers/replace_let_with_if_let.rs index 174ff1fb4..a49292c97 100644 --- a/crates/ra_assists/src/handlers/replace_let_with_if_let.rs +++ b/crates/ra_assists/src/handlers/replace_let_with_if_let.rs @@ -45,8 +45,7 @@ pub(crate) fn replace_let_with_if_let(acc: &mut Assists, ctx: &AssistContext) -> let target = let_kw.text_range(); acc.add( - AssistId("replace_let_with_if_let"), - AssistKind::RefactorRewrite, + AssistId("replace_let_with_if_let", AssistKind::RefactorRewrite), "Replace with if-let", target, |edit| { diff --git a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs index 5e06f7f0e..dfd314abf 100644 --- a/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs +++ b/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs @@ -37,8 +37,7 @@ pub(crate) fn replace_qualified_name_with_use( let target = path.syntax().text_range(); acc.add( - AssistId("replace_qualified_name_with_use"), - AssistKind::RefactorRewrite, + AssistId("replace_qualified_name_with_use", AssistKind::RefactorRewrite), "Replace qualified path with use", target, |builder| { diff --git a/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs b/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs index 5f9705be1..e5a4bb23c 100644 --- a/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs +++ b/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs @@ -47,8 +47,7 @@ pub(crate) fn replace_unwrap_with_match(acc: &mut Assists, ctx: &AssistContext) let happy_variant = TryEnum::from_ty(&ctx.sema, &ty)?.happy_case(); let target = method_call.syntax().text_range(); acc.add( - AssistId("replace_unwrap_with_match"), - AssistKind::RefactorRewrite, + AssistId("replace_unwrap_with_match", AssistKind::RefactorRewrite), "Replace unwrap with match", target, |builder| { diff --git a/crates/ra_assists/src/handlers/split_import.rs b/crates/ra_assists/src/handlers/split_import.rs index a27b6230a..4ca5c3ca1 100644 --- a/crates/ra_assists/src/handlers/split_import.rs +++ b/crates/ra_assists/src/handlers/split_import.rs @@ -28,7 +28,7 @@ pub(crate) fn split_import(acc: &mut Assists, ctx: &AssistContext) -> Option<()> } let target = colon_colon.text_range(); - acc.add(AssistId("split_import"), AssistKind::RefactorRewrite, "Split import", target, |edit| { + acc.add(AssistId("split_import", AssistKind::RefactorRewrite), "Split import", target, |edit| { edit.replace_ast(use_tree, new_tree); }) } diff --git a/crates/ra_assists/src/handlers/unwrap_block.rs b/crates/ra_assists/src/handlers/unwrap_block.rs index a66fba7c3..8b38695a9 100644 --- a/crates/ra_assists/src/handlers/unwrap_block.rs +++ b/crates/ra_assists/src/handlers/unwrap_block.rs @@ -27,7 +27,7 @@ use crate::{AssistContext, AssistId, AssistKind, Assists}; // } // ``` pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()> { - let assist_id = AssistId("unwrap_block"); + let assist_id = AssistId("unwrap_block", AssistKind::RefactorRewrite); let assist_label = "Unwrap block"; let l_curly_token = ctx.find_token_at_offset(T!['{'])?; @@ -50,47 +50,35 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()> let ancestor_then_branch = ancestor.then_branch()?; let target = then_branch.syntax().text_range(); - return acc.add( - assist_id, - AssistKind::Refactor, - assist_label, - target, - |edit| { - let range_to_del_else_if = TextRange::new( - ancestor_then_branch.syntax().text_range().end(), - l_curly_token.text_range().start(), - ); - let range_to_del_rest = TextRange::new( - then_branch.syntax().text_range().end(), - if_expr.syntax().text_range().end(), - ); - - edit.delete(range_to_del_rest); - edit.delete(range_to_del_else_if); - edit.replace( - target, - update_expr_string(then_branch.to_string(), &[' ', '{']), - ); - }, - ); + return acc.add(assist_id, assist_label, target, |edit| { + let range_to_del_else_if = TextRange::new( + ancestor_then_branch.syntax().text_range().end(), + l_curly_token.text_range().start(), + ); + let range_to_del_rest = TextRange::new( + then_branch.syntax().text_range().end(), + if_expr.syntax().text_range().end(), + ); + + edit.delete(range_to_del_rest); + edit.delete(range_to_del_else_if); + edit.replace( + target, + update_expr_string(then_branch.to_string(), &[' ', '{']), + ); + }); } } else { let target = block.syntax().text_range(); - return acc.add( - assist_id, - AssistKind::RefactorRewrite, - assist_label, - target, - |edit| { - let range_to_del = TextRange::new( - then_branch.syntax().text_range().end(), - l_curly_token.text_range().start(), - ); + return acc.add(assist_id, assist_label, target, |edit| { + let range_to_del = TextRange::new( + then_branch.syntax().text_range().end(), + l_curly_token.text_range().start(), + ); - edit.delete(range_to_del); - edit.replace(target, update_expr_string(block.to_string(), &[' ', '{'])); - }, - ); + edit.delete(range_to_del); + edit.replace(target, update_expr_string(block.to_string(), &[' ', '{'])); + }); } } _ => return None, @@ -98,7 +86,7 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()> let unwrapped = unwrap_trivial_block(block); let target = unwrapped.syntax().text_range(); - acc.add(assist_id, AssistKind::RefactorRewrite, assist_label, target, |builder| { + acc.add(assist_id, assist_label, target, |builder| { builder.replace( parent.syntax().text_range(), update_expr_string(unwrapped.to_string(), &[' ', '{', '\n']), -- cgit v1.2.3