diff options
author | Laurențiu Nicola <[email protected]> | 2019-02-12 17:58:36 +0000 |
---|---|---|
committer | Laurențiu Nicola <[email protected]> | 2019-02-12 18:35:10 +0000 |
commit | 040fb91387105bca7f2b6fcb845f836217b0a7ee (patch) | |
tree | a32088b2fb598cb231dc50de4de73a23fe6ee8b8 /crates/ra_ide_api/src | |
parent | 3e367b5760117856bd178d637f740a7f0cd1ffee (diff) |
Filter attributes from the completion details/label
Diffstat (limited to 'crates/ra_ide_api/src')
3 files changed, 49 insertions, 0 deletions
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<String> { | |||
71 | .children() | 71 | .children() |
72 | .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body | 72 | .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body |
73 | .filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments | 73 | .filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments |
74 | .filter(|child| ast::Attr::cast(child).is_none()) // Filter out attributes | ||
74 | .map(|node| node.text().to_string()) | 75 | .map(|node| node.text().to_string()) |
75 | .collect(); | 76 | .collect(); |
76 | label | 77 | label |
@@ -86,6 +87,7 @@ pub fn const_label(node: &ast::ConstDef) -> String { | |||
86 | .syntax() | 87 | .syntax() |
87 | .children() | 88 | .children() |
88 | .filter(|child| ast::Comment::cast(child).is_none()) | 89 | .filter(|child| ast::Comment::cast(child).is_none()) |
90 | .filter(|child| ast::Attr::cast(child).is_none()) | ||
89 | .map(|node| node.text().to_string()) | 91 | .map(|node| node.text().to_string()) |
90 | .collect(); | 92 | .collect(); |
91 | 93 | ||
@@ -97,6 +99,7 @@ pub fn type_label(node: &ast::TypeDef) -> String { | |||
97 | .syntax() | 99 | .syntax() |
98 | .children() | 100 | .children() |
99 | .filter(|child| ast::Comment::cast(child).is_none()) | 101 | .filter(|child| ast::Comment::cast(child).is_none()) |
102 | .filter(|child| ast::Attr::cast(child).is_none()) | ||
100 | .map(|node| node.text().to_string()) | 103 | .map(|node| node.text().to_string()) |
101 | .collect(); | 104 | .collect(); |
102 | 105 | ||
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 | |||
@@ -180,6 +180,26 @@ mod tests { | |||
180 | } | 180 | } |
181 | 181 | ||
182 | #[test] | 182 | #[test] |
183 | fn test_method_attr_filtering() { | ||
184 | check_ref_completion( | ||
185 | "method_attr_filtering", | ||
186 | r" | ||
187 | struct A {} | ||
188 | impl A { | ||
189 | #[inline] | ||
190 | fn the_method(&self) { | ||
191 | let x = 1; | ||
192 | let y = 2; | ||
193 | } | ||
194 | } | ||
195 | fn foo(a: A) { | ||
196 | a.<|> | ||
197 | } | ||
198 | ", | ||
199 | ); | ||
200 | } | ||
201 | |||
202 | #[test] | ||
183 | fn test_tuple_field_completion() { | 203 | fn test_tuple_field_completion() { |
184 | check_ref_completion( | 204 | check_ref_completion( |
185 | "tuple_field_completion", | 205 | "tuple_field_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 @@ | |||
1 | --- | ||
2 | created: "2019-02-12T18:32:09.428929418Z" | ||
3 | creator: [email protected] | ||
4 | source: crates/ra_ide_api/src/completion/completion_item.rs | ||
5 | expression: kind_completions | ||
6 | --- | ||
7 | [ | ||
8 | CompletionItem { | ||
9 | completion_kind: Reference, | ||
10 | label: "the_method", | ||
11 | kind: Some( | ||
12 | Method | ||
13 | ), | ||
14 | detail: Some( | ||
15 | "fn the_method(&self)" | ||
16 | ), | ||
17 | documentation: None, | ||
18 | lookup: None, | ||
19 | insert_text: Some( | ||
20 | "the_method()$0" | ||
21 | ), | ||
22 | insert_text_format: Snippet, | ||
23 | source_range: [249; 249), | ||
24 | text_edit: None | ||
25 | } | ||
26 | ] | ||