aboutsummaryrefslogtreecommitdiff
path: root/crates/assists
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists')
-rw-r--r--crates/assists/src/handlers/generate_enum_match_method.rs10
-rw-r--r--crates/assists/src/tests/generated.rs1
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
135impl Variant { 140impl 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 {
180enum Variant { Undefined } 186enum Variant { Undefined }
181 187
182impl Variant { 188impl 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
206impl Variant { 213impl 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 ae7b400e2..aa97a9882 100644
--- a/crates/assists/src/tests/generated.rs
+++ b/crates/assists/src/tests/generated.rs
@@ -451,6 +451,7 @@ enum Version {
451} 451}
452 452
453impl Version { 453impl Version {
454 /// Returns `true` if the version is [`Minor`].
454 fn is_minor(&self) -> bool { 455 fn is_minor(&self) -> bool {
455 matches!(self, Self::Minor) 456 matches!(self, Self::Minor)
456 } 457 }