Add function signature to CompletionItem detail
This commit is contained in:
parent
595a2f9900
commit
070a980224
@ -366,6 +366,28 @@ impl Function {
|
||||
Some(comments)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn label(&self, db: &impl HirDatabase) -> Option<String> {
|
||||
let def_loc = self.def_id.loc(db);
|
||||
let syntax = db.file_item(def_loc.source_item_id);
|
||||
let node = ast::FnDef::cast(&syntax).expect("fn def should point to FnDef node");
|
||||
|
||||
let label: String = if let Some(body) = node.body() {
|
||||
let body_range = body.syntax().range();
|
||||
let label: String = node
|
||||
.syntax()
|
||||
.children()
|
||||
.filter(|child| !child.range().is_subrange(&body_range)) // Filter out body
|
||||
.filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments
|
||||
.map(|node| node.text().to_string())
|
||||
.collect();
|
||||
label
|
||||
} else {
|
||||
node.syntax().text().to_string()
|
||||
};
|
||||
|
||||
Some(label.trim().to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
|
@ -263,6 +263,10 @@ impl Builder {
|
||||
self.documentation = Some(docs);
|
||||
}
|
||||
|
||||
if let Some(label) = function.label(ctx.db) {
|
||||
self.detail = Some(label);
|
||||
}
|
||||
|
||||
self.kind = Some(CompletionItemKind::Function);
|
||||
self
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-22T14:45:00.858540400+00:00"
|
||||
created: "2019-01-22T15:38:19.841148300+00:00"
|
||||
creator: insta@0.4.0
|
||||
expression: kind_completions
|
||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
@ -25,7 +25,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn quux()"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-22T14:45:00.860535200+00:00"
|
||||
created: "2019-01-22T15:38:19.863089100+00:00"
|
||||
creator: insta@0.4.0
|
||||
expression: kind_completions
|
||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
@ -39,7 +39,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn quux()"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-22T14:45:00.871506600+00:00"
|
||||
created: "2019-01-22T15:38:19.881041600+00:00"
|
||||
creator: insta@0.4.0
|
||||
expression: kind_completions
|
||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
@ -39,7 +39,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn quux(x: i32)"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-22T14:45:00.797704900+00:00"
|
||||
created: "2019-01-22T15:38:19.788294+00:00"
|
||||
creator: insta@0.4.0
|
||||
expression: kind_completions
|
||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn main()"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: None,
|
||||
@ -25,7 +27,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn frobnicate()"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: None,
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-22T14:45:00.801693300+00:00"
|
||||
created: "2019-01-22T15:38:19.815217100+00:00"
|
||||
creator: insta@0.4.0
|
||||
expression: kind_completions
|
||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"pub fn foo()"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: None,
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-22T14:45:00.912397100+00:00"
|
||||
created: "2019-01-22T15:38:19.914951100+00:00"
|
||||
creator: insta@0.4.0
|
||||
expression: kind_completions
|
||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
@ -25,7 +25,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn foo() ->"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-22T14:45:00.932343200+00:00"
|
||||
created: "2019-01-22T15:38:19.919937+00:00"
|
||||
creator: insta@0.4.0
|
||||
expression: kind_completions
|
||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn no_args()"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
@ -27,7 +29,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn main()"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-22T14:45:00.995180+00:00"
|
||||
created: "2019-01-22T15:38:19.996733+00:00"
|
||||
creator: insta@0.4.0
|
||||
expression: kind_completions
|
||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn main()"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
@ -27,7 +29,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn with_args(x: i32, y: String)"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-22T14:45:00.546394900+00:00"
|
||||
created: "2019-01-22T15:38:19.541947400+00:00"
|
||||
creator: insta@0.4.0
|
||||
expression: kind_completions
|
||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Method
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn the_method(&self)"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-22T14:45:00.874497400+00:00"
|
||||
created: "2019-01-22T15:38:19.896999400+00:00"
|
||||
creator: insta@0.4.0
|
||||
expression: kind_completions
|
||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn quux()"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-22T14:45:00.875495300+00:00"
|
||||
created: "2019-01-22T15:38:19.896002200+00:00"
|
||||
creator: insta@0.4.0
|
||||
expression: kind_completions
|
||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn quux()"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
|
@ -25,7 +25,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Function
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn x() ->"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-22T14:45:00.552379600+00:00"
|
||||
created: "2019-01-22T15:38:19.541947400+00:00"
|
||||
creator: insta@0.4.0
|
||||
expression: kind_completions
|
||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
@ -27,7 +27,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Method
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn foo(&self)"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
|
@ -1,5 +1,5 @@
|
||||
---
|
||||
created: "2019-01-22T14:45:00.552379600+00:00"
|
||||
created: "2019-01-22T15:38:19.541947400+00:00"
|
||||
creator: insta@0.4.0
|
||||
expression: kind_completions
|
||||
source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
@ -27,7 +27,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
|
||||
kind: Some(
|
||||
Method
|
||||
),
|
||||
detail: None,
|
||||
detail: Some(
|
||||
"fn foo(self)"
|
||||
),
|
||||
documentation: None,
|
||||
lookup: None,
|
||||
insert_text: Some(
|
||||
|
Loading…
x
Reference in New Issue
Block a user