Skip to content

Commit d90bd63

Browse files
committed
Add doc gen to the generate_enum_match_method assist
1 parent dfd7513 commit d90bd63

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

crates/assists/src/handlers/generate_enum_match_method.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use crate::{utils::find_struct_impl, AssistContext, AssistId, AssistKind, Assist
2525
// }
2626
//
2727
// impl Version {
28+
// /// Returns `true` if the version is [`Minor`].
2829
// fn is_minor(&self) -> bool {
2930
// matches!(self, Self::Minor)
3031
// }
@@ -39,6 +40,7 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext)
3940
return None;
4041
}
4142

43+
let enum_lowercase_name = to_lower_snake_case(&parent_enum.name()?.to_string());
4244
let fn_name = to_lower_snake_case(&variant_name.to_string());
4345

4446
// 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)
6466

6567
format_to!(
6668
buf,
67-
" {}fn is_{}(&self) -> bool {{
69+
" /// Returns `true` if the {} is [`{}`].
70+
{}fn is_{}(&self) -> bool {{
6871
matches!(self, Self::{})
6972
}}",
73+
enum_lowercase_name,
74+
variant_name,
7075
vis,
7176
fn_name,
7277
variant_name
@@ -133,6 +138,7 @@ enum Variant {
133138
}
134139
135140
impl Variant {
141+
/// Returns `true` if the variant is [`Minor`].
136142
fn is_minor(&self) -> bool {
137143
matches!(self, Self::Minor)
138144
}
@@ -180,6 +186,7 @@ enum Variant {
180186
enum Variant { Undefined }
181187
182188
impl Variant {
189+
/// Returns `true` if the variant is [`Undefined`].
183190
fn is_undefined(&self) -> bool {
184191
matches!(self, Self::Undefined)
185192
}
@@ -204,6 +211,7 @@ pub(crate) enum Variant {
204211
}
205212
206213
impl Variant {
214+
/// Returns `true` if the variant is [`Minor`].
207215
pub(crate) fn is_minor(&self) -> bool {
208216
matches!(self, Self::Minor)
209217
}

crates/assists/src/tests/generated.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ enum Version {
451451
}
452452
453453
impl Version {
454+
/// Returns `true` if the version is [`Minor`].
454455
fn is_minor(&self) -> bool {
455456
matches!(self, Self::Minor)
456457
}

0 commit comments

Comments
 (0)