mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Filter attributes from the completion details/label
This commit is contained in:
parent
3e367b5760
commit
040fb91387
3 changed files with 49 additions and 0 deletions
|
@ -71,6 +71,7 @@ pub fn function_label(node: &ast::FnDef) -> Option<String> {
|
||||||
.children()
|
.children()
|
||||||
.filter(|child| !child.range().is_subrange(&body_range)) // Filter out body
|
.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::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())
|
.map(|node| node.text().to_string())
|
||||||
.collect();
|
.collect();
|
||||||
label
|
label
|
||||||
|
@ -86,6 +87,7 @@ pub fn const_label(node: &ast::ConstDef) -> String {
|
||||||
.syntax()
|
.syntax()
|
||||||
.children()
|
.children()
|
||||||
.filter(|child| ast::Comment::cast(child).is_none())
|
.filter(|child| ast::Comment::cast(child).is_none())
|
||||||
|
.filter(|child| ast::Attr::cast(child).is_none())
|
||||||
.map(|node| node.text().to_string())
|
.map(|node| node.text().to_string())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
@ -97,6 +99,7 @@ pub fn type_label(node: &ast::TypeDef) -> String {
|
||||||
.syntax()
|
.syntax()
|
||||||
.children()
|
.children()
|
||||||
.filter(|child| ast::Comment::cast(child).is_none())
|
.filter(|child| ast::Comment::cast(child).is_none())
|
||||||
|
.filter(|child| ast::Attr::cast(child).is_none())
|
||||||
.map(|node| node.text().to_string())
|
.map(|node| node.text().to_string())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
|
@ -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]
|
#[test]
|
||||||
fn test_tuple_field_completion() {
|
fn test_tuple_field_completion() {
|
||||||
check_ref_completion(
|
check_ref_completion(
|
||||||
|
|
|
@ -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
|
||||||
|
}
|
||||||
|
]
|
Loading…
Add table
Add a link
Reference in a new issue