aboutsummaryrefslogtreecommitdiff
path: root/crates/assists/src/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'crates/assists/src/handlers')
-rw-r--r--crates/assists/src/handlers/generate_enum_match_method.rs10
1 files changed, 9 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 2345a61c1..4cf66b5d5 100644
--- a/crates/assists/src/handlers/generate_enum_match_method.rs
+++ b/crates/assists/src/handlers/generate_enum_match_method.rs
@@ -28,6 +28,7 @@ use crate::{
28// } 28// }
29// 29//
30// impl Version { 30// impl Version {
31// /// Returns `true` if the version is [`Minor`].
31// fn is_minor(&self) -> bool { 32// fn is_minor(&self) -> bool {
32// matches!(self, Self::Minor) 33// matches!(self, Self::Minor)
33// } 34// }
@@ -42,6 +43,7 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext)
42 return None; 43 return None;
43 } 44 }
44 45
46 let enum_lowercase_name = to_lower_snake_case(&parent_enum.name()?.to_string());
45 let fn_name = to_lower_snake_case(&variant_name.to_string()); 47 let fn_name = to_lower_snake_case(&variant_name.to_string());
46 48
47 // Return early if we've found an existing new fn 49 // Return early if we've found an existing new fn
@@ -66,9 +68,12 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext)
66 let vis = parent_enum.visibility().map_or(String::new(), |v| format!("{} ", v)); 68 let vis = parent_enum.visibility().map_or(String::new(), |v| format!("{} ", v));
67 format_to!( 69 format_to!(
68 buf, 70 buf,
69 " {}fn is_{}(&self) -> bool {{ 71 " /// Returns `true` if the {} is [`{}`].
72 {}fn is_{}(&self) -> bool {{
70 matches!(self, Self::{}) 73 matches!(self, Self::{})
71 }}", 74 }}",
75 enum_lowercase_name,
76 variant_name,
72 vis, 77 vis,
73 fn_name, 78 fn_name,
74 variant_name 79 variant_name
@@ -125,6 +130,7 @@ enum Variant {
125} 130}
126 131
127impl Variant { 132impl Variant {
133 /// Returns `true` if the variant is [`Minor`].
128 fn is_minor(&self) -> bool { 134 fn is_minor(&self) -> bool {
129 matches!(self, Self::Minor) 135 matches!(self, Self::Minor)
130 } 136 }
@@ -172,6 +178,7 @@ enum Variant {
172enum Variant { Undefined } 178enum Variant { Undefined }
173 179
174impl Variant { 180impl Variant {
181 /// Returns `true` if the variant is [`Undefined`].
175 fn is_undefined(&self) -> bool { 182 fn is_undefined(&self) -> bool {
176 matches!(self, Self::Undefined) 183 matches!(self, Self::Undefined)
177 } 184 }
@@ -196,6 +203,7 @@ pub(crate) enum Variant {
196} 203}
197 204
198impl Variant { 205impl Variant {
206 /// Returns `true` if the variant is [`Minor`].
199 pub(crate) fn is_minor(&self) -> bool { 207 pub(crate) fn is_minor(&self) -> bool {
200 matches!(self, Self::Minor) 208 matches!(self, Self::Minor)
201 } 209 }