From 040fb91387105bca7f2b6fcb845f836217b0a7ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lauren=C8=9Biu=20Nicola?= Date: Tue, 12 Feb 2019 19:58:36 +0200 Subject: Filter attributes from the completion details/label --- crates/ra_ide_api/src/completion.rs | 3 +++ crates/ra_ide_api/src/completion/complete_dot.rs | 20 +++++++++++++++++ .../completion_item__method_attr_filtering.snap | 26 ++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap diff --git a/crates/ra_ide_api/src/completion.rs b/crates/ra_ide_api/src/completion.rs index 2b94931c6..4a38d62bb 100644 --- a/crates/ra_ide_api/src/completion.rs +++ b/crates/ra_ide_api/src/completion.rs @@ -71,6 +71,7 @@ pub fn function_label(node: &ast::FnDef) -> Option { .children() .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body .filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments + .filter(|child| ast::Attr::cast(child).is_none()) // Filter out attributes .map(|node| node.text().to_string()) .collect(); label @@ -86,6 +87,7 @@ pub fn const_label(node: &ast::ConstDef) -> String { .syntax() .children() .filter(|child| ast::Comment::cast(child).is_none()) + .filter(|child| ast::Attr::cast(child).is_none()) .map(|node| node.text().to_string()) .collect(); @@ -97,6 +99,7 @@ pub fn type_label(node: &ast::TypeDef) -> String { .syntax() .children() .filter(|child| ast::Comment::cast(child).is_none()) + .filter(|child| ast::Attr::cast(child).is_none()) .map(|node| node.text().to_string()) .collect(); diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index a673dbdcf..be839345f 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -179,6 +179,26 @@ mod tests { ); } + #[test] + fn test_method_attr_filtering() { + check_ref_completion( + "method_attr_filtering", + r" + struct A {} + impl A { + #[inline] + fn the_method(&self) { + let x = 1; + let y = 2; + } + } + fn foo(a: A) { + a.<|> + } + ", + ); + } + #[test] fn test_tuple_field_completion() { check_ref_completion( diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap new file mode 100644 index 000000000..46f9fa971 --- /dev/null +++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__method_attr_filtering.snap @@ -0,0 +1,26 @@ +--- +created: "2019-02-12T18:32:09.428929418Z" +creator: insta@0.6.2 +source: crates/ra_ide_api/src/completion/completion_item.rs +expression: kind_completions +--- +[ + CompletionItem { + completion_kind: Reference, + label: "the_method", + kind: Some( + Method + ), + detail: Some( + "fn the_method(&self)" + ), + documentation: None, + lookup: None, + insert_text: Some( + "the_method()$0" + ), + insert_text_format: Snippet, + source_range: [249; 249), + text_edit: None + } +] -- cgit v1.2.3