about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCôme ALLART <come.allart@etu.emse.fr>2021-12-07 18:02:18 +0100
committerCôme ALLART <come.allart@etu.emse.fr>2021-12-07 18:02:18 +0100
commit220137f1cfd8ec1bf1f4d4e755a6ce4ea1421032 (patch)
treee497fe961194d3175181d056a43aaa18336ceb31
parent3a82548c5e04395ba63add086461671e89d80262 (diff)
downloadrust-220137f1cfd8ec1bf1f4d4e755a6ce4ea1421032.tar.gz
rust-220137f1cfd8ec1bf1f4d4e755a6ce4ea1421032.zip
fix: disable assist for documented functions
-rw-r--r--crates/ide_assists/src/handlers/generate_documentation_template.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/crates/ide_assists/src/handlers/generate_documentation_template.rs b/crates/ide_assists/src/handlers/generate_documentation_template.rs
index 09179af6138..b69fc1332b4 100644
--- a/crates/ide_assists/src/handlers/generate_documentation_template.rs
+++ b/crates/ide_assists/src/handlers/generate_documentation_template.rs
@@ -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));
         },
     )
@@ -502,6 +502,17 @@ mod ParentPrivateModule {
     }
 
     #[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(
             generate_documentation_template,