diff options
Diffstat (limited to 'crates/assists')
-rw-r--r-- | crates/assists/src/handlers/generate_enum_match_method.rs | 10 | ||||
-rw-r--r-- | crates/assists/src/tests/generated.rs | 1 |
2 files changed, 10 insertions, 1 deletions
diff --git a/crates/assists/src/handlers/generate_enum_match_method.rs b/crates/assists/src/handlers/generate_enum_match_method.rs index 270b438b7..ee89d4208 100644 --- a/crates/assists/src/handlers/generate_enum_match_method.rs +++ b/crates/assists/src/handlers/generate_enum_match_method.rs | |||
@@ -25,6 +25,7 @@ use crate::{utils::find_struct_impl, AssistContext, AssistId, AssistKind, Assist | |||
25 | // } | 25 | // } |
26 | // | 26 | // |
27 | // impl Version { | 27 | // impl Version { |
28 | // /// Returns `true` if the version is [`Minor`]. | ||
28 | // fn is_minor(&self) -> bool { | 29 | // fn is_minor(&self) -> bool { |
29 | // matches!(self, Self::Minor) | 30 | // matches!(self, Self::Minor) |
30 | // } | 31 | // } |
@@ -39,6 +40,7 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext) | |||
39 | return None; | 40 | return None; |
40 | } | 41 | } |
41 | 42 | ||
43 | let enum_lowercase_name = to_lower_snake_case(&parent_enum.name()?.to_string()); | ||
42 | let fn_name = to_lower_snake_case(&variant_name.to_string()); | 44 | let fn_name = to_lower_snake_case(&variant_name.to_string()); |
43 | 45 | ||
44 | // Return early if we've found an existing new fn | 46 | // Return early if we've found an existing new fn |
@@ -64,9 +66,12 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext) | |||
64 | 66 | ||
65 | format_to!( | 67 | format_to!( |
66 | buf, | 68 | buf, |
67 | " {}fn is_{}(&self) -> bool {{ | 69 | " /// Returns `true` if the {} is [`{}`]. |
70 | {}fn is_{}(&self) -> bool {{ | ||
68 | matches!(self, Self::{}) | 71 | matches!(self, Self::{}) |
69 | }}", | 72 | }}", |
73 | enum_lowercase_name, | ||
74 | variant_name, | ||
70 | vis, | 75 | vis, |
71 | fn_name, | 76 | fn_name, |
72 | variant_name | 77 | variant_name |
@@ -133,6 +138,7 @@ enum Variant { | |||
133 | } | 138 | } |
134 | 139 | ||
135 | impl Variant { | 140 | impl Variant { |
141 | /// Returns `true` if the variant is [`Minor`]. | ||
136 | fn is_minor(&self) -> bool { | 142 | fn is_minor(&self) -> bool { |
137 | matches!(self, Self::Minor) | 143 | matches!(self, Self::Minor) |
138 | } | 144 | } |
@@ -180,6 +186,7 @@ enum Variant { | |||
180 | enum Variant { Undefined } | 186 | enum Variant { Undefined } |
181 | 187 | ||
182 | impl Variant { | 188 | impl Variant { |
189 | /// Returns `true` if the variant is [`Undefined`]. | ||
183 | fn is_undefined(&self) -> bool { | 190 | fn is_undefined(&self) -> bool { |
184 | matches!(self, Self::Undefined) | 191 | matches!(self, Self::Undefined) |
185 | } | 192 | } |
@@ -204,6 +211,7 @@ pub(crate) enum Variant { | |||
204 | } | 211 | } |
205 | 212 | ||
206 | impl Variant { | 213 | impl Variant { |
214 | /// Returns `true` if the variant is [`Minor`]. | ||
207 | pub(crate) fn is_minor(&self) -> bool { | 215 | pub(crate) fn is_minor(&self) -> bool { |
208 | matches!(self, Self::Minor) | 216 | matches!(self, Self::Minor) |
209 | } | 217 | } |
diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs index 960815bd9..0dbb05f2a 100644 --- a/crates/assists/src/tests/generated.rs +++ b/crates/assists/src/tests/generated.rs | |||
@@ -478,6 +478,7 @@ enum Version { | |||
478 | } | 478 | } |
479 | 479 | ||
480 | impl Version { | 480 | impl Version { |
481 | /// Returns `true` if the version is [`Minor`]. | ||
481 | fn is_minor(&self) -> bool { | 482 | fn is_minor(&self) -> bool { |
482 | matches!(self, Self::Minor) | 483 | matches!(self, Self::Minor) |
483 | } | 484 | } |