about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-11-15 11:45:02 +0000
committerbors <bors@rust-lang.org>2022-11-15 11:45:02 +0000
commit8292dd8026b352cdc5302042fcaccbed5edc7c72 (patch)
tree51fc3a1a1ac9fa37bcb38ecba602a7c3339f5032
parenta516b90dee0d3e0f31cd74ca0891758c2daa8bac (diff)
parent7e77d4e310fa36c9ede7905be5971776a075be16 (diff)
downloadrust-8292dd8026b352cdc5302042fcaccbed5edc7c72.tar.gz
rust-8292dd8026b352cdc5302042fcaccbed5edc7c72.zip
Auto merge of #13623 - jonas-schievink:strip-trait-item-completions, r=jonas-schievink
fix: Strip comments and attributes off of all trait item completions

Previously, this was done in several places redundantly, but not for all items. It was also untested. This PR fixes that.
-rw-r--r--crates/ide-completion/src/completions/item_list/trait_impl.rs82
1 files changed, 76 insertions, 6 deletions
diff --git a/crates/ide-completion/src/completions/item_list/trait_impl.rs b/crates/ide-completion/src/completions/item_list/trait_impl.rs
index b612cdc4a17..7384a3f2d80 100644
--- a/crates/ide-completion/src/completions/item_list/trait_impl.rs
+++ b/crates/ide-completion/src/completions/item_list/trait_impl.rs
@@ -236,9 +236,7 @@ fn get_transformed_assoc_item(
     );
 
     transform.apply(assoc_item.syntax());
-    if let ast::AssocItem::Fn(func) = &assoc_item {
-        func.remove_attrs_and_docs();
-    }
+    assoc_item.remove_attrs_and_docs();
     Some(assoc_item)
 }
 
@@ -335,7 +333,6 @@ fn add_const_impl(
 }
 
 fn make_const_compl_syntax(const_: &ast::Const, needs_whitespace: bool) -> String {
-    const_.remove_attrs_and_docs();
     let const_ = if needs_whitespace {
         insert_whitespace_into_node::insert_ws_into(const_.syntax().clone())
     } else {
@@ -359,8 +356,6 @@ fn make_const_compl_syntax(const_: &ast::Const, needs_whitespace: bool) -> Strin
 }
 
 fn function_declaration(node: &ast::Fn, needs_whitespace: bool) -> String {
-    node.remove_attrs_and_docs();
-
     let node = if needs_whitespace {
         insert_whitespace_into_node::insert_ws_into(node.syntax().clone())
     } else {
@@ -1212,4 +1207,79 @@ impl<'b> Tr<'b> for () {
 "#,
         );
     }
+
+    #[test]
+    fn strips_comments() {
+        check_edit(
+            "fn func",
+            r#"
+trait Tr {
+    /// docs
+    #[attr]
+    fn func();
+}
+impl Tr for () {
+    $0
+}
+"#,
+            r#"
+trait Tr {
+    /// docs
+    #[attr]
+    fn func();
+}
+impl Tr for () {
+    fn func() {
+    $0
+}
+}
+"#,
+        );
+        check_edit(
+            "const C",
+            r#"
+trait Tr {
+    /// docs
+    #[attr]
+    const C: usize;
+}
+impl Tr for () {
+    $0
+}
+"#,
+            r#"
+trait Tr {
+    /// docs
+    #[attr]
+    const C: usize;
+}
+impl Tr for () {
+    const C: usize = $0;
+}
+"#,
+        );
+        check_edit(
+            "type Item",
+            r#"
+trait Tr {
+    /// docs
+    #[attr]
+    type Item;
+}
+impl Tr for () {
+    $0
+}
+"#,
+            r#"
+trait Tr {
+    /// docs
+    #[attr]
+    type Item;
+}
+impl Tr for () {
+    type Item = $0;
+}
+"#,
+        );
+    }
 }