Skip to content

Commit 61324a8

Browse files
bors[bot]lnicola
andcommitted
Merge #811
811: Filter attributes from the completion details/label r=kjeremy a=lnicola Before: ![image](https://user-images.githubusercontent.com/308347/52657254-efba9a00-2f00-11e9-952f-901910cfc459.png) After: ![image](https://user-images.githubusercontent.com/308347/52657278-fb0dc580-2f00-11e9-9267-8aff44c93447.png) Co-authored-by: Laurențiu Nicola <[email protected]>
2 parents 24287d0 + 040fb91 commit 61324a8

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

crates/ra_ide_api/src/completion.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ pub fn function_label(node: &ast::FnDef) -> Option<String> {
7171
.children()
7272
.filter(|child| !child.range().is_subrange(&body_range)) // Filter out body
7373
.filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments
74+
.filter(|child| ast::Attr::cast(child).is_none()) // Filter out attributes
7475
.map(|node| node.text().to_string())
7576
.collect();
7677
label
@@ -86,6 +87,7 @@ pub fn const_label(node: &ast::ConstDef) -> String {
8687
.syntax()
8788
.children()
8889
.filter(|child| ast::Comment::cast(child).is_none())
90+
.filter(|child| ast::Attr::cast(child).is_none())
8991
.map(|node| node.text().to_string())
9092
.collect();
9193

@@ -97,6 +99,7 @@ pub fn type_label(node: &ast::TypeDef) -> String {
9799
.syntax()
98100
.children()
99101
.filter(|child| ast::Comment::cast(child).is_none())
102+
.filter(|child| ast::Attr::cast(child).is_none())
100103
.map(|node| node.text().to_string())
101104
.collect();
102105

crates/ra_ide_api/src/completion/complete_dot.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,26 @@ mod tests {
179179
);
180180
}
181181

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+
182202
#[test]
183203
fn test_tuple_field_completion() {
184204
check_ref_completion(
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
created: "2019-02-12T18:32:09.428929418Z"
3+
creator: insta@0.6.2
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+
]

0 commit comments

Comments
 (0)