Skip to content

Commit 220137f

Browse files
author
Côme ALLART
committed
fix: disable assist for documented functions
1 parent 3a82548 commit 220137f

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

crates/ide_assists/src/handlers/generate_documentation_template.rs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ pub(crate) fn generate_documentation_template(
4141
) -> Option<()> {
4242
let name = ctx.find_node_at_offset::<ast::Name>()?;
4343
let ast_func = name.syntax().parent().and_then(ast::Fn::cast)?;
44-
if is_in_trait_impl(&ast_func) || !is_public(&ast_func) {
44+
if is_in_trait_impl(&ast_func)
45+
|| !is_public(&ast_func)
46+
|| ast_func.doc_comments().next().is_some()
47+
{
4548
return None;
4649
}
4750

@@ -70,9 +73,6 @@ pub(crate) fn generate_documentation_template(
7073
doc_lines.append(&mut lines);
7174
}
7275
}
73-
if ast_func.doc_comments().next().is_some() {
74-
doc_lines.push("--- OLD VERSION BELOW ---".into());
75-
}
7676
builder.insert(text_range.start(), documentation_from_lines(doc_lines, indent_level));
7777
},
7878
)
@@ -501,6 +501,17 @@ mod ParentPrivateModule {
501501
);
502502
}
503503

504+
#[test]
505+
fn not_applicable_if_function_already_documented() {
506+
check_assist_not_applicable(
507+
generate_documentation_template,
508+
r#"
509+
/// Some documentation here
510+
pub fn $0documented_function() {}
511+
"#,
512+
);
513+
}
514+
504515
#[test]
505516
fn supports_noop_function() {
506517
check_assist(

0 commit comments

Comments
 (0)