11867: create generate is, as, try_into group r=Veykril a=jakevossen5

Fixes #11636 

In `generate_enum_projection_method.rs`, the changes to the function are from `cargo fmt`, I made the same change as I did in `generate_enum_is_method.rs`.

Co-authored-by: Jake Vossen <jake@vossen.dev>
This commit is contained in:
bors[bot] 2022-04-01 10:18:15 +00:00 committed by GitHub
commit 244ee65bbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 19 deletions

View file

@ -1,3 +1,4 @@
use ide_db::assists::GroupLabel;
use stdx::to_lower_snake_case; use stdx::to_lower_snake_case;
use syntax::ast::HasVisibility; use syntax::ast::HasVisibility;
use syntax::ast::{self, AstNode, HasName}; use syntax::ast::{self, AstNode, HasName};
@ -54,7 +55,8 @@ pub(crate) fn generate_enum_is_method(acc: &mut Assists, ctx: &AssistContext) ->
let impl_def = find_struct_impl(ctx, &parent_enum, &fn_name)?; let impl_def = find_struct_impl(ctx, &parent_enum, &fn_name)?;
let target = variant.syntax().text_range(); let target = variant.syntax().text_range();
acc.add( acc.add_group(
&GroupLabel("Generate `is_`,`as_`,`try_into_`".to_owned()),
AssistId("generate_enum_is_method", AssistKind::Generate), AssistId("generate_enum_is_method", AssistKind::Generate),
"Generate an `is_` method for an enum variant", "Generate an `is_` method for an enum variant",
target, target,

View file

@ -1,3 +1,4 @@
use ide_db::assists::GroupLabel;
use itertools::Itertools; use itertools::Itertools;
use stdx::to_lower_snake_case; use stdx::to_lower_snake_case;
use syntax::ast::HasVisibility; use syntax::ast::HasVisibility;
@ -139,7 +140,12 @@ fn generate_enum_projection_method(
let impl_def = find_struct_impl(ctx, &parent_enum, &fn_name)?; let impl_def = find_struct_impl(ctx, &parent_enum, &fn_name)?;
let target = variant.syntax().text_range(); let target = variant.syntax().text_range();
acc.add(AssistId(assist_id, AssistKind::Generate), assist_description, target, |builder| { acc.add_group(
&GroupLabel("Generate `is_`,`as_`,`try_into_`".to_owned()),
AssistId(assist_id, AssistKind::Generate),
assist_description,
target,
|builder| {
let vis = parent_enum.visibility().map_or(String::new(), |v| format!("{} ", v)); let vis = parent_enum.visibility().map_or(String::new(), |v| format!("{} ", v));
let method = format!( let method = format!(
" {0}fn {1}({2}) -> {3}{4}{5} {{ " {0}fn {1}({2}) -> {3}{4}{5} {{
@ -163,7 +169,8 @@ fn generate_enum_projection_method(
); );
add_method_to_adt(builder, &parent_enum, impl_def, &method); add_method_to_adt(builder, &parent_enum, impl_def, &method);
}) },
)
} }
#[cfg(test)] #[cfg(test)]