]> git.lizzy.rs Git - rust.git/commitdiff
fix: disable assist for documented functions
authorCôme ALLART <come.allart@etu.emse.fr>
Tue, 7 Dec 2021 17:02:18 +0000 (18:02 +0100)
committerCôme ALLART <come.allart@etu.emse.fr>
Tue, 7 Dec 2021 17:02:18 +0000 (18:02 +0100)
crates/ide_assists/src/handlers/generate_documentation_template.rs

index 09179af6138ef3781511434d5d76c6eb596654ad..b69fc1332b4431dffea793eb68a5f0fb80815a00 100644 (file)
@@ -41,7 +41,10 @@ pub(crate) fn generate_documentation_template(
 ) -> Option<()> {
     let name = ctx.find_node_at_offset::<ast::Name>()?;
     let ast_func = name.syntax().parent().and_then(ast::Fn::cast)?;
-    if is_in_trait_impl(&ast_func) || !is_public(&ast_func) {
+    if is_in_trait_impl(&ast_func)
+        || !is_public(&ast_func)
+        || ast_func.doc_comments().next().is_some()
+    {
         return None;
     }
 
@@ -70,9 +73,6 @@ pub(crate) fn generate_documentation_template(
                     doc_lines.append(&mut lines);
                 }
             }
-            if ast_func.doc_comments().next().is_some() {
-                doc_lines.push("--- OLD VERSION BELOW ---".into());
-            }
             builder.insert(text_range.start(), documentation_from_lines(doc_lines, indent_level));
         },
     )
@@ -501,6 +501,17 @@ pub fn pr$0ivate() {}
         );
     }
 
+    #[test]
+    fn not_applicable_if_function_already_documented() {
+        check_assist_not_applicable(
+            generate_documentation_template,
+            r#"
+/// Some documentation here
+pub fn $0documented_function() {}
+"#,
+        );
+    }
+
     #[test]
     fn supports_noop_function() {
         check_assist(