From d90bd635366d9223762b3b1c7381405a1f12f9d4 Mon Sep 17 00:00:00 2001
From: Yoshua Wuyts <yoshuawuyts@gmail.com>
Date: Fri, 5 Feb 2021 15:35:24 +0100
Subject: [PATCH] Add doc gen to the `generate_enum_match_method` assist

---
 .../assists/src/handlers/generate_enum_match_method.rs | 10 +++++++++-
 crates/assists/src/tests/generated.rs                  |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/crates/assists/src/handlers/generate_enum_match_method.rs b/crates/assists/src/handlers/generate_enum_match_method.rs
index 270b438b705..ee89d420854 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
 // }
 //
 // impl Version {
+//     /// Returns `true` if the version is [`Minor`].
 //     fn is_minor(&self) -> bool {
 //         matches!(self, Self::Minor)
 //     }
@@ -39,6 +40,7 @@ pub(crate) fn generate_enum_match_method(acc: &mut Assists, ctx: &AssistContext)
         return None;
     }
 
+    let enum_lowercase_name = to_lower_snake_case(&parent_enum.name()?.to_string());
     let fn_name = to_lower_snake_case(&variant_name.to_string());
 
     // 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)
 
             format_to!(
                 buf,
-                "    {}fn is_{}(&self) -> bool {{
+                "    /// Returns `true` if the {} is [`{}`].
+    {}fn is_{}(&self) -> bool {{
         matches!(self, Self::{})
     }}",
+                enum_lowercase_name,
+                variant_name,
                 vis,
                 fn_name,
                 variant_name
@@ -133,6 +138,7 @@ enum Variant {
 }
 
 impl Variant {
+    /// Returns `true` if the variant is [`Minor`].
     fn is_minor(&self) -> bool {
         matches!(self, Self::Minor)
     }
@@ -180,6 +186,7 @@ enum Variant {
 enum Variant { Undefined }
 
 impl Variant {
+    /// Returns `true` if the variant is [`Undefined`].
     fn is_undefined(&self) -> bool {
         matches!(self, Self::Undefined)
     }
@@ -204,6 +211,7 @@ pub(crate) enum Variant {
 }
 
 impl Variant {
+    /// Returns `true` if the variant is [`Minor`].
     pub(crate) fn is_minor(&self) -> bool {
         matches!(self, Self::Minor)
     }
diff --git a/crates/assists/src/tests/generated.rs b/crates/assists/src/tests/generated.rs
index ae7b400e208..aa97a98821a 100644
--- a/crates/assists/src/tests/generated.rs
+++ b/crates/assists/src/tests/generated.rs
@@ -451,6 +451,7 @@ enum Version {
 }
 
 impl Version {
+    /// Returns `true` if the version is [`Minor`].
     fn is_minor(&self) -> bool {
         matches!(self, Self::Minor)
     }