aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_assists/src')
-rw-r--r--crates/ra_assists/src/handlers/generate_derive.rs47
-rw-r--r--crates/ra_assists/src/handlers/generate_from_impl_for_enum.rs2
-rw-r--r--crates/ra_assists/src/handlers/generate_function.rs2
-rw-r--r--crates/ra_assists/src/handlers/generate_impl.rs2
-rw-r--r--crates/ra_assists/src/handlers/generate_new.rs2
-rw-r--r--crates/ra_assists/src/lib.rs1
6 files changed, 31 insertions, 25 deletions
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<
29 let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?; 29 let nominal = ctx.find_node_at_offset::<ast::NominalDef>()?;
30 let node_start = derive_insertion_offset(&nominal)?; 30 let node_start = derive_insertion_offset(&nominal)?;
31 let target = nominal.syntax().text_range(); 31 let target = nominal.syntax().text_range();
32 acc.add(AssistId("generate_derive", AssistKind::None), "Add `#[derive]`", target, |builder| { 32 acc.add(
33 let derive_attr = nominal 33 AssistId("generate_derive", AssistKind::Generate),
34 .attrs() 34 "Add `#[derive]`",
35 .filter_map(|x| x.as_simple_call()) 35 target,
36 .filter(|(name, _arg)| name == "derive") 36 |builder| {
37 .map(|(_name, arg)| arg) 37 let derive_attr = nominal
38 .next(); 38 .attrs()
39 match derive_attr { 39 .filter_map(|x| x.as_simple_call())
40 None => { 40 .filter(|(name, _arg)| name == "derive")
41 builder.insert_snippet(cap, node_start, "#[derive($0)]\n"); 41 .map(|(_name, arg)| arg)
42 } 42 .next();
43 Some(tt) => { 43 match derive_attr {
44 // Just move the cursor. 44 None => {
45 builder.insert_snippet( 45 builder.insert_snippet(cap, node_start, "#[derive($0)]\n");
46 cap, 46 }
47 tt.syntax().text_range().end() - TextSize::of(')'), 47 Some(tt) => {
48 "$0", 48 // Just move the cursor.
49 ) 49 builder.insert_snippet(
50 } 50 cap,
51 }; 51 tt.syntax().text_range().end() - TextSize::of(')'),
52 }) 52 "$0",
53 )
54 }
55 };
56 },
57 )
53} 58}
54 59
55// Insert `derive` after doc comments. 60// 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
45 45
46 let target = variant.syntax().text_range(); 46 let target = variant.syntax().text_range();
47 acc.add( 47 acc.add(
48 AssistId("generate_from_impl_for_enum", AssistKind::Refactor), 48 AssistId("generate_from_impl_for_enum", AssistKind::Generate),
49 "Generate `From` impl for this enum variant", 49 "Generate `From` impl for this enum variant",
50 target, 50 target,
51 |edit| { 51 |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
63 63
64 let target = call.syntax().text_range(); 64 let target = call.syntax().text_range();
65 acc.add( 65 acc.add(
66 AssistId("generate_function", AssistKind::None), 66 AssistId("generate_function", AssistKind::Generate),
67 format!("Generate `{}` function", function_builder.fn_name), 67 format!("Generate `{}` function", function_builder.fn_name),
68 target, 68 target,
69 |builder| { 69 |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<()
27 let name = nominal.name()?; 27 let name = nominal.name()?;
28 let target = nominal.syntax().text_range(); 28 let target = nominal.syntax().text_range();
29 acc.add( 29 acc.add(
30 AssistId("generate_impl", AssistKind::Refactor), 30 AssistId("generate_impl", AssistKind::Generate),
31 format!("Generate impl for `{}`", name), 31 format!("Generate impl for `{}`", name),
32 target, 32 target,
33 |edit| { 33 |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<()>
42 let impl_def = find_struct_impl(&ctx, &strukt)?; 42 let impl_def = find_struct_impl(&ctx, &strukt)?;
43 43
44 let target = strukt.syntax().text_range(); 44 let target = strukt.syntax().text_range();
45 acc.add(AssistId("generate_new", AssistKind::None), "Generate `new`", target, |builder| { 45 acc.add(AssistId("generate_new", AssistKind::Generate), "Generate `new`", target, |builder| {
46 let mut buf = String::with_capacity(512); 46 let mut buf = String::with_capacity(512);
47 47
48 if impl_def.is_some() { 48 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;
30pub enum AssistKind { 30pub enum AssistKind {
31 None, 31 None,
32 QuickFix, 32 QuickFix,
33 Generate,
33 Refactor, 34 Refactor,
34 RefactorExtract, 35 RefactorExtract,
35 RefactorInline, 36 RefactorInline,