aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy A. Kolb <[email protected]>2019-01-22 15:54:50 +0000
committerJeremy A. Kolb <[email protected]>2019-01-22 15:54:50 +0000
commit070a9802246123c79709271c9ba6fddd6f888813 (patch)
tree2b04dcbbd2738cb916c957fecad89a1732b8d908
parent595a2f9900d052d0c5cc3529602aec0cbcd52614 (diff)
Add function signature to CompletionItem detail
-rw-r--r--crates/ra_hir/src/code_model_api.rs22
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs4
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_for.snap6
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_if_let.snap6
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_let.snap6
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call.snap10
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_in_use_item.snap6
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__dont_show_both_completions_for_shadowing.snap6
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls1.snap10
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls2.snap10
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap6
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__module_items.snap6
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__module_items_in_nested_modules.snap6
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__return_type.snap4
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap6
-rw-r--r--crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap6
16 files changed, 90 insertions, 30 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs
index 9ae620efd..21ca36265 100644
--- a/crates/ra_hir/src/code_model_api.rs
+++ b/crates/ra_hir/src/code_model_api.rs
@@ -366,6 +366,28 @@ impl Function {
366 Some(comments) 366 Some(comments)
367 } 367 }
368 } 368 }
369
370 pub fn label(&self, db: &impl HirDatabase) -> Option<String> {
371 let def_loc = self.def_id.loc(db);
372 let syntax = db.file_item(def_loc.source_item_id);
373 let node = ast::FnDef::cast(&syntax).expect("fn def should point to FnDef node");
374
375 let label: String = if let Some(body) = node.body() {
376 let body_range = body.syntax().range();
377 let label: String = node
378 .syntax()
379 .children()
380 .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body
381 .filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments
382 .map(|node| node.text().to_string())
383 .collect();
384 label
385 } else {
386 node.syntax().text().to_string()
387 };
388
389 Some(label.trim().to_owned())
390 }
369} 391}
370 392
371#[derive(Debug, Clone, PartialEq, Eq, Hash)] 393#[derive(Debug, Clone, PartialEq, Eq, Hash)]
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index d70c36889..b720a1382 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -263,6 +263,10 @@ impl Builder {
263 self.documentation = Some(docs); 263 self.documentation = Some(docs);
264 } 264 }
265 265
266 if let Some(label) = function.label(ctx.db) {
267 self.detail = Some(label);
268 }
269
266 self.kind = Some(CompletionItemKind::Function); 270 self.kind = Some(CompletionItemKind::Function);
267 self 271 self
268 } 272 }
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_for.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_for.snap
index 3d8d5af78..eb806ad62 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_for.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_for.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-22T14:45:00.858540400+00:00" 2created: "2019-01-22T15:38:19.841148300+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
@@ -25,7 +25,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
25 kind: Some( 25 kind: Some(
26 Function 26 Function
27 ), 27 ),
28 detail: None, 28 detail: Some(
29 "fn quux()"
30 ),
29 documentation: None, 31 documentation: None,
30 lookup: None, 32 lookup: None,
31 insert_text: Some( 33 insert_text: Some(
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_if_let.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_if_let.snap
index 7ed1d5ccb..4bb28c7e8 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_if_let.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_if_let.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-22T14:45:00.860535200+00:00" 2created: "2019-01-22T15:38:19.863089100+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
@@ -39,7 +39,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
39 kind: Some( 39 kind: Some(
40 Function 40 Function
41 ), 41 ),
42 detail: None, 42 detail: Some(
43 "fn quux()"
44 ),
43 documentation: None, 45 documentation: None,
44 lookup: None, 46 lookup: None,
45 insert_text: Some( 47 insert_text: Some(
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_let.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_let.snap
index 95581122d..0579d00ec 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_let.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__bindings_from_let.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-22T14:45:00.871506600+00:00" 2created: "2019-01-22T15:38:19.881041600+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
@@ -39,7 +39,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
39 kind: Some( 39 kind: Some(
40 Function 40 Function
41 ), 41 ),
42 detail: None, 42 detail: Some(
43 "fn quux(x: i32)"
44 ),
43 documentation: None, 45 documentation: None,
44 lookup: None, 46 lookup: None,
45 insert_text: Some( 47 insert_text: Some(
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call.snap
index 18d8b3fb3..091bf581e 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_if_already_call.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-22T14:45:00.797704900+00:00" 2created: "2019-01-22T15:38:19.788294+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
@@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
11 kind: Some( 11 kind: Some(
12 Function 12 Function
13 ), 13 ),
14 detail: None, 14 detail: Some(
15 "fn main()"
16 ),
15 documentation: None, 17 documentation: None,
16 lookup: None, 18 lookup: None,
17 insert_text: None, 19 insert_text: None,
@@ -25,7 +27,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
25 kind: Some( 27 kind: Some(
26 Function 28 Function
27 ), 29 ),
28 detail: None, 30 detail: Some(
31 "fn frobnicate()"
32 ),
29 documentation: None, 33 documentation: None,
30 lookup: None, 34 lookup: None,
31 insert_text: None, 35 insert_text: None,
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_in_use_item.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_in_use_item.snap
index 8bf7bf06c..3bc3f5f38 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_in_use_item.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_render_function_parens_in_use_item.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-22T14:45:00.801693300+00:00" 2created: "2019-01-22T15:38:19.815217100+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
@@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
11 kind: Some( 11 kind: Some(
12 Function 12 Function
13 ), 13 ),
14 detail: None, 14 detail: Some(
15 "pub fn foo()"
16 ),
15 documentation: None, 17 documentation: None,
16 lookup: None, 18 lookup: None,
17 insert_text: None, 19 insert_text: None,
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_show_both_completions_for_shadowing.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_show_both_completions_for_shadowing.snap
index 5844254e1..3e88d8c8e 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_show_both_completions_for_shadowing.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__dont_show_both_completions_for_shadowing.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-22T14:45:00.912397100+00:00" 2created: "2019-01-22T15:38:19.914951100+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
@@ -25,7 +25,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
25 kind: Some( 25 kind: Some(
26 Function 26 Function
27 ), 27 ),
28 detail: None, 28 detail: Some(
29 "fn foo() ->"
30 ),
29 documentation: None, 31 documentation: None,
30 lookup: None, 32 lookup: None,
31 insert_text: Some( 33 insert_text: Some(
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls1.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls1.snap
index 732a87382..b30a4c9e9 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls1.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls1.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-22T14:45:00.932343200+00:00" 2created: "2019-01-22T15:38:19.919937+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
@@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
11 kind: Some( 11 kind: Some(
12 Function 12 Function
13 ), 13 ),
14 detail: None, 14 detail: Some(
15 "fn no_args()"
16 ),
15 documentation: None, 17 documentation: None,
16 lookup: None, 18 lookup: None,
17 insert_text: Some( 19 insert_text: Some(
@@ -27,7 +29,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
27 kind: Some( 29 kind: Some(
28 Function 30 Function
29 ), 31 ),
30 detail: None, 32 detail: Some(
33 "fn main()"
34 ),
31 documentation: None, 35 documentation: None,
32 lookup: None, 36 lookup: None,
33 insert_text: Some( 37 insert_text: Some(
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls2.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls2.snap
index 2431b3276..c524f3587 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls2.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__inserts_parens_for_function_calls2.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-22T14:45:00.995180+00:00" 2created: "2019-01-22T15:38:19.996733+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
@@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
11 kind: Some( 11 kind: Some(
12 Function 12 Function
13 ), 13 ),
14 detail: None, 14 detail: Some(
15 "fn main()"
16 ),
15 documentation: None, 17 documentation: None,
16 lookup: None, 18 lookup: None,
17 insert_text: Some( 19 insert_text: Some(
@@ -27,7 +29,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
27 kind: Some( 29 kind: Some(
28 Function 30 Function
29 ), 31 ),
30 detail: None, 32 detail: Some(
33 "fn with_args(x: i32, y: String)"
34 ),
31 documentation: None, 35 documentation: None,
32 lookup: None, 36 lookup: None,
33 insert_text: Some( 37 insert_text: Some(
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap
index c294de5cb..ffeac0bf4 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__method_completion.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-22T14:45:00.546394900+00:00" 2created: "2019-01-22T15:38:19.541947400+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
@@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
11 kind: Some( 11 kind: Some(
12 Method 12 Method
13 ), 13 ),
14 detail: None, 14 detail: Some(
15 "fn the_method(&self)"
16 ),
15 documentation: None, 17 documentation: None,
16 lookup: None, 18 lookup: None,
17 insert_text: Some( 19 insert_text: Some(
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__module_items.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__module_items.snap
index 032516ab4..df9677ba3 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__module_items.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__module_items.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-22T14:45:00.874497400+00:00" 2created: "2019-01-22T15:38:19.896999400+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
@@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
11 kind: Some( 11 kind: Some(
12 Function 12 Function
13 ), 13 ),
14 detail: None, 14 detail: Some(
15 "fn quux()"
16 ),
15 documentation: None, 17 documentation: None,
16 lookup: None, 18 lookup: None,
17 insert_text: Some( 19 insert_text: Some(
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__module_items_in_nested_modules.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__module_items_in_nested_modules.snap
index b33babaf0..f4b38feb0 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__module_items_in_nested_modules.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__module_items_in_nested_modules.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-22T14:45:00.875495300+00:00" 2created: "2019-01-22T15:38:19.896002200+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
@@ -11,7 +11,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
11 kind: Some( 11 kind: Some(
12 Function 12 Function
13 ), 13 ),
14 detail: None, 14 detail: Some(
15 "fn quux()"
16 ),
15 documentation: None, 17 documentation: None,
16 lookup: None, 18 lookup: None,
17 insert_text: Some( 19 insert_text: Some(
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__return_type.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__return_type.snap
index 24dbe6bb0..e6819f231 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__return_type.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__return_type.snap
@@ -25,7 +25,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
25 kind: Some( 25 kind: Some(
26 Function 26 Function
27 ), 27 ),
28 detail: None, 28 detail: Some(
29 "fn x() ->"
30 ),
29 documentation: None, 31 documentation: None,
30 lookup: None, 32 lookup: None,
31 insert_text: Some( 33 insert_text: Some(
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap
index 9ee668b35..5ef140b28 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_autoderef.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-22T14:45:00.552379600+00:00" 2created: "2019-01-22T15:38:19.541947400+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
@@ -27,7 +27,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
27 kind: Some( 27 kind: Some(
28 Method 28 Method
29 ), 29 ),
30 detail: None, 30 detail: Some(
31 "fn foo(&self)"
32 ),
31 documentation: None, 33 documentation: None,
32 lookup: None, 34 lookup: None,
33 insert_text: Some( 35 insert_text: Some(
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap
index b9d70ea3f..b7903c5bc 100644
--- a/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap
+++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__struct_field_completion_self.snap
@@ -1,5 +1,5 @@
1--- 1---
2created: "2019-01-22T14:45:00.552379600+00:00" 2created: "2019-01-22T15:38:19.541947400+00:00"
3creator: [email protected] 3creator: [email protected]
4expression: kind_completions 4expression: kind_completions
5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs" 5source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
@@ -27,7 +27,9 @@ source: "crates\\ra_ide_api\\src\\completion\\completion_item.rs"
27 kind: Some( 27 kind: Some(
28 Method 28 Method
29 ), 29 ),
30 detail: None, 30 detail: Some(
31 "fn foo(self)"
32 ),
31 documentation: None, 33 documentation: None,
32 lookup: None, 34 lookup: None,
33 insert_text: Some( 35 insert_text: Some(