From d09f6923009943cee1b24571c2905c3c0bfb49c7 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 3 Jul 2020 19:14:42 +0200 Subject: Add AssistKind::Generate --- crates/ra_assists/src/handlers/generate_derive.rs | 47 ++++++++++++---------- .../src/handlers/generate_from_impl_for_enum.rs | 2 +- .../ra_assists/src/handlers/generate_function.rs | 2 +- crates/ra_assists/src/handlers/generate_impl.rs | 2 +- crates/ra_assists/src/handlers/generate_new.rs | 2 +- crates/ra_assists/src/lib.rs | 1 + 6 files changed, 31 insertions(+), 25 deletions(-) (limited to 'crates/ra_assists/src') diff --git a/crates/ra_assists/src/handlers/generate_derive.rs b/crates/ra_assists/src/handlers/generate_derive.rs index 8fc522eef..6ccf39900 100644 --- a/crates/ra_assists/src/handlers/generate_derive.rs +++ b/crates/ra_assists/src/handlers/generate_derive.rs @@ -29,27 +29,32 @@ pub(crate) fn generate_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("generate_derive", AssistKind::None), "Add `#[derive]`", target, |builder| { - let derive_attr = nominal - .attrs() - .filter_map(|x| x.as_simple_call()) - .filter(|(name, _arg)| name == "derive") - .map(|(_name, arg)| arg) - .next(); - match derive_attr { - None => { - builder.insert_snippet(cap, node_start, "#[derive($0)]\n"); - } - Some(tt) => { - // Just move the cursor. - builder.insert_snippet( - cap, - tt.syntax().text_range().end() - TextSize::of(')'), - "$0", - ) - } - }; - }) + acc.add( + AssistId("generate_derive", AssistKind::Generate), + "Add `#[derive]`", + target, + |builder| { + let derive_attr = nominal + .attrs() + .filter_map(|x| x.as_simple_call()) + .filter(|(name, _arg)| name == "derive") + .map(|(_name, arg)| arg) + .next(); + match derive_attr { + None => { + builder.insert_snippet(cap, node_start, "#[derive($0)]\n"); + } + Some(tt) => { + // Just move the cursor. + builder.insert_snippet( + cap, + tt.syntax().text_range().end() - TextSize::of(')'), + "$0", + ) + } + }; + }, + ) } // Insert `derive` after doc comments. diff --git a/crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs b/crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs index e781be61e..a347e3c2e 100644 --- a/crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs +++ b/crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs @@ -45,7 +45,7 @@ pub(crate) fn generate_from_impl_for_enum(acc: &mut Assists, ctx: &AssistContext let target = variant.syntax().text_range(); acc.add( - AssistId("generate_from_impl_for_enum", AssistKind::Refactor), + AssistId("generate_from_impl_for_enum", AssistKind::Generate), "Generate `From` impl for this enum variant", target, |edit| { diff --git a/crates/ra_assists/src/handlers/generate_function.rs b/crates/ra_assists/src/handlers/generate_function.rs index 35162791e..b721b96bb 100644 --- a/crates/ra_assists/src/handlers/generate_function.rs +++ b/crates/ra_assists/src/handlers/generate_function.rs @@ -63,7 +63,7 @@ pub(crate) fn generate_function(acc: &mut Assists, ctx: &AssistContext) -> Optio let target = call.syntax().text_range(); acc.add( - AssistId("generate_function", AssistKind::None), + AssistId("generate_function", AssistKind::Generate), format!("Generate `{}` function", function_builder.fn_name), target, |builder| { diff --git a/crates/ra_assists/src/handlers/generate_impl.rs b/crates/ra_assists/src/handlers/generate_impl.rs index 5f287afb6..cbbac1d7f 100644 --- a/crates/ra_assists/src/handlers/generate_impl.rs +++ b/crates/ra_assists/src/handlers/generate_impl.rs @@ -27,7 +27,7 @@ pub(crate) fn generate_impl(acc: &mut Assists, ctx: &AssistContext) -> Option<() let name = nominal.name()?; let target = nominal.syntax().text_range(); acc.add( - AssistId("generate_impl", AssistKind::Refactor), + AssistId("generate_impl", AssistKind::Generate), format!("Generate impl for `{}`", name), target, |edit| { diff --git a/crates/ra_assists/src/handlers/generate_new.rs b/crates/ra_assists/src/handlers/generate_new.rs index b37bba761..e27def1d8 100644 --- a/crates/ra_assists/src/handlers/generate_new.rs +++ b/crates/ra_assists/src/handlers/generate_new.rs @@ -42,7 +42,7 @@ pub(crate) fn generate_new(acc: &mut Assists, ctx: &AssistContext) -> Option<()> let impl_def = find_struct_impl(&ctx, &strukt)?; let target = strukt.syntax().text_range(); - acc.add(AssistId("generate_new", AssistKind::None), "Generate `new`", target, |builder| { + acc.add(AssistId("generate_new", AssistKind::Generate), "Generate `new`", target, |builder| { let mut buf = String::with_capacity(512); if impl_def.is_some() { diff --git a/crates/ra_assists/src/lib.rs b/crates/ra_assists/src/lib.rs index 5b9def052..3d61fbded 100644 --- a/crates/ra_assists/src/lib.rs +++ b/crates/ra_assists/src/lib.rs @@ -30,6 +30,7 @@ pub use assist_config::AssistConfig; pub enum AssistKind { None, QuickFix, + Generate, Refactor, RefactorExtract, RefactorInline, -- cgit v1.2.3