diff options
author | Ekaterina Babshukova <[email protected]> | 2019-07-23 17:24:54 +0100 |
---|---|---|
committer | Ekaterina Babshukova <[email protected]> | 2019-07-23 17:26:27 +0100 |
commit | 8e49bb664a03c29e25055a5a2ec03aa055462423 (patch) | |
tree | 3b555fbdb1cf4d8c9c2a67e34b29ec8ebc31b2cb /crates | |
parent | 5f3ff157e3efe9f4fe2461bca1a0caaa5d2c72e5 (diff) |
show local variable types in completion
Diffstat (limited to 'crates')
6 files changed, 30 insertions, 9 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs index fc9bc33d2..c2c6921cb 100644 --- a/crates/ra_hir/src/source_binder.rs +++ b/crates/ra_hir/src/source_binder.rs | |||
@@ -256,6 +256,14 @@ impl SourceAnalyzer { | |||
256 | Some(self.infer.as_ref()?[pat_id].clone()) | 256 | Some(self.infer.as_ref()?[pat_id].clone()) |
257 | } | 257 | } |
258 | 258 | ||
259 | pub fn type_of_pat_by_id( | ||
260 | &self, | ||
261 | _db: &impl HirDatabase, | ||
262 | pat_id: expr::PatId, | ||
263 | ) -> Option<crate::Ty> { | ||
264 | Some(self.infer.as_ref()?[pat_id].clone()) | ||
265 | } | ||
266 | |||
259 | pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { | 267 | pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option<Function> { |
260 | let expr_id = self.body_source_map.as_ref()?.node_expr(&call.clone().into())?; | 268 | let expr_id = self.body_source_map.as_ref()?.node_expr(&call.clone().into())?; |
261 | self.infer.as_ref()?.method_resolution(expr_id) | 269 | self.infer.as_ref()?.method_resolution(expr_id) |
diff --git a/crates/ra_ide_api/src/completion/presentation.rs b/crates/ra_ide_api/src/completion/presentation.rs index 98060947a..5cf55a496 100644 --- a/crates/ra_ide_api/src/completion/presentation.rs +++ b/crates/ra_ide_api/src/completion/presentation.rs | |||
@@ -1,5 +1,5 @@ | |||
1 | //! This modules takes care of rendering various defenitions as completion items. | 1 | //! This modules takes care of rendering various defenitions as completion items. |
2 | use hir::{Docs, HasSource, HirDisplay, PerNs, Resolution}; | 2 | use hir::{Docs, HasSource, HirDisplay, PerNs, Resolution, Ty}; |
3 | use join_to_string::join; | 3 | use join_to_string::join; |
4 | use ra_syntax::ast::NameOwner; | 4 | use ra_syntax::ast::NameOwner; |
5 | use test_utils::tested_by; | 5 | use test_utils::tested_by; |
@@ -80,10 +80,18 @@ impl Completions { | |||
80 | None, | 80 | None, |
81 | ), | 81 | ), |
82 | }; | 82 | }; |
83 | CompletionItem::new(completion_kind, ctx.source_range(), local_name) | 83 | |
84 | .kind(kind) | 84 | let mut completion_item = |
85 | .set_documentation(docs) | 85 | CompletionItem::new(completion_kind, ctx.source_range(), local_name); |
86 | .add_to(self) | 86 | if let Resolution::LocalBinding(pat_id) = def { |
87 | let ty = ctx | ||
88 | .analyzer | ||
89 | .type_of_pat_by_id(ctx.db, pat_id.clone()) | ||
90 | .filter(|t| t != &Ty::Unknown) | ||
91 | .map(|t| t.display(ctx.db).to_string()); | ||
92 | completion_item = completion_item.set_detail(ty); | ||
93 | }; | ||
94 | completion_item.kind(kind).set_documentation(docs).add_to(self) | ||
87 | } | 95 | } |
88 | 96 | ||
89 | pub(crate) fn add_function(&mut self, ctx: &CompletionContext, func: hir::Function) { | 97 | pub(crate) fn add_function(&mut self, ctx: &CompletionContext, func: hir::Function) { |
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 2a22201ad..f94477b43 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 | --- |
2 | created: "2019-05-23T22:23:35.122168608Z" | 2 | created: "2019-07-23T16:11:48.828805910Z" |
3 | creator: [email protected] | 3 | creator: [email protected] |
4 | source: crates/ra_ide_api/src/completion/completion_item.rs | 4 | source: crates/ra_ide_api/src/completion/completion_item.rs |
5 | expression: kind_completions | 5 | expression: kind_completions |
@@ -18,6 +18,7 @@ expression: kind_completions | |||
18 | delete: [214; 214), | 18 | delete: [214; 214), |
19 | insert: "b", | 19 | insert: "b", |
20 | kind: Binding, | 20 | kind: Binding, |
21 | detail: "i32", | ||
21 | }, | 22 | }, |
22 | CompletionItem { | 23 | CompletionItem { |
23 | label: "quux", | 24 | label: "quux", |
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 b9a5dc9c8..590e2a820 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 | --- |
2 | created: "2019-05-23T22:23:35.122797188Z" | 2 | created: "2019-07-23T16:11:48.828811567Z" |
3 | creator: [email protected] | 3 | creator: [email protected] |
4 | source: crates/ra_ide_api/src/completion/completion_item.rs | 4 | source: crates/ra_ide_api/src/completion/completion_item.rs |
5 | expression: kind_completions | 5 | expression: kind_completions |
@@ -19,6 +19,7 @@ expression: kind_completions | |||
19 | delete: [79; 79), | 19 | delete: [79; 79), |
20 | insert: "x", | 20 | insert: "x", |
21 | kind: Binding, | 21 | kind: Binding, |
22 | detail: "i32", | ||
22 | }, | 23 | }, |
23 | CompletionItem { | 24 | CompletionItem { |
24 | label: "y", | 25 | label: "y", |
@@ -26,5 +27,6 @@ expression: kind_completions | |||
26 | delete: [79; 79), | 27 | delete: [79; 79), |
27 | insert: "y", | 28 | insert: "y", |
28 | kind: Binding, | 29 | kind: Binding, |
30 | detail: "i32", | ||
29 | }, | 31 | }, |
30 | ] | 32 | ] |
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 57434210d..158a2e5b9 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 | --- |
2 | created: "2019-05-23T22:23:35.142044205Z" | 2 | created: "2019-07-23T16:11:48.860949870Z" |
3 | creator: [email protected] | 3 | creator: [email protected] |
4 | source: crates/ra_ide_api/src/completion/completion_item.rs | 4 | source: crates/ra_ide_api/src/completion/completion_item.rs |
5 | expression: kind_completions | 5 | expression: kind_completions |
@@ -11,6 +11,7 @@ expression: kind_completions | |||
11 | delete: [126; 126), | 11 | delete: [126; 126), |
12 | insert: "bar", | 12 | insert: "bar", |
13 | kind: Binding, | 13 | kind: Binding, |
14 | detail: "i32", | ||
14 | }, | 15 | }, |
15 | CompletionItem { | 16 | CompletionItem { |
16 | label: "foo", | 17 | label: "foo", |
diff --git a/crates/ra_ide_api/src/completion/snapshots/completion_item__self_in_methods.snap b/crates/ra_ide_api/src/completion/snapshots/completion_item__self_in_methods.snap index e1af94870..b7bcbe864 100644 --- a/crates/ra_ide_api/src/completion/snapshots/completion_item__self_in_methods.snap +++ b/crates/ra_ide_api/src/completion/snapshots/completion_item__self_in_methods.snap | |||
@@ -1,5 +1,5 @@ | |||
1 | --- | 1 | --- |
2 | created: "2019-05-23T22:23:35.141900902Z" | 2 | created: "2019-07-23T16:11:48.859812318Z" |
3 | creator: [email protected] | 3 | creator: [email protected] |
4 | source: crates/ra_ide_api/src/completion/completion_item.rs | 4 | source: crates/ra_ide_api/src/completion/completion_item.rs |
5 | expression: kind_completions | 5 | expression: kind_completions |
@@ -18,5 +18,6 @@ expression: kind_completions | |||
18 | delete: [25; 25), | 18 | delete: [25; 25), |
19 | insert: "self", | 19 | insert: "self", |
20 | kind: Binding, | 20 | kind: Binding, |
21 | detail: "&{unknown}", | ||
21 | }, | 22 | }, |
22 | ] | 23 | ] |