From 220137f1cfd8ec1bf1f4d4e755a6ce4ea1421032 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=B4me=20ALLART?= Date: Tue, 7 Dec 2021 18:02:18 +0100 Subject: [PATCH] fix: disable assist for documented functions --- .../generate_documentation_template.rs | 19 +++++++++++++++---- 1 file 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::()?; 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( -- 2.44.0