aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-23 07:27:09 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-23 07:27:09 +0000
commit488326ffa74bea2773eed9c1849e9d3b9eac9b2d (patch)
tree9a5fe407bb209df945f08e2042a23edde9a006ce /crates/ra_ide_api/src
parentf90783fc5309e1835b22aa65d071efb9cf3eb9df (diff)
parenta3472f8fe16a359f9ea7a12e7b4920894921421e (diff)
Merge #598
598: Add function signature to CompletionItem detail r=matklad a=kjeremy Co-authored-by: Jeremy A. Kolb <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r--crates/ra_ide_api/src/completion/completion_item.rs29
-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
15 files changed, 92 insertions, 31 deletions
diff --git a/crates/ra_ide_api/src/completion/completion_item.rs b/crates/ra_ide_api/src/completion/completion_item.rs
index d70c36889..680fd8d1b 100644
--- a/crates/ra_ide_api/src/completion/completion_item.rs
+++ b/crates/ra_ide_api/src/completion/completion_item.rs
@@ -1,7 +1,10 @@
1use hir::PerNs; 1use hir::PerNs;
2 2
3use crate::completion::completion_context::CompletionContext; 3use crate::completion::completion_context::CompletionContext;
4use ra_syntax::TextRange; 4use ra_syntax::{
5 ast::{self, AstNode},
6 TextRange
7};
5use ra_text_edit::TextEdit; 8use ra_text_edit::TextEdit;
6 9
7/// `CompletionItem` describes a single completion variant in the editor pop-up. 10/// `CompletionItem` describes a single completion variant in the editor pop-up.
@@ -263,6 +266,10 @@ impl Builder {
263 self.documentation = Some(docs); 266 self.documentation = Some(docs);
264 } 267 }
265 268
269 if let Some(label) = function_label(ctx, function) {
270 self.detail = Some(label);
271 }
272
266 self.kind = Some(CompletionItemKind::Function); 273 self.kind = Some(CompletionItemKind::Function);
267 self 274 self
268 } 275 }
@@ -299,6 +306,26 @@ impl Into<Vec<CompletionItem>> for Completions {
299 } 306 }
300} 307}
301 308
309fn function_label(ctx: &CompletionContext, function: hir::Function) -> Option<String> {
310 let node = function.source(ctx.db).1;
311
312 let label: String = if let Some(body) = node.body() {
313 let body_range = body.syntax().range();
314 let label: String = node
315 .syntax()
316 .children()
317 .filter(|child| !child.range().is_subrange(&body_range)) // Filter out body
318 .filter(|child| ast::Comment::cast(child).is_none()) // Filter out comments
319 .map(|node| node.text().to_string())
320 .collect();
321 label
322 } else {
323 node.syntax().text().to_string()
324 };
325
326 Some(label.trim().to_owned())
327}
328
302#[cfg(test)] 329#[cfg(test)]
303pub(crate) fn check_completion(test_name: &str, code: &str, kind: CompletionKind) { 330pub(crate) fn check_completion(test_name: &str, code: &str, kind: CompletionKind) {
304 use crate::mock_analysis::{single_file_with_position, analysis_and_position}; 331 use crate::mock_analysis::{single_file_with_position, analysis_and_position};
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(