diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-11-26 11:05:05 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-11-26 11:05:05 +0000 |
commit | 500e022f7decbee29a693b0f0dd2f63789a99e5a (patch) | |
tree | 2f7839288ce5676a89c6d6062cbaf70544e0beed /crates/ra_ide_api/src/completion/complete_dot.rs | |
parent | 5901cc736074bbc4d780a8e45079d405ab2cec4b (diff) | |
parent | e5eadb339039e21718d382c0b3d02a4bf053b3f4 (diff) |
Merge #2398
2398: WIP: introduce hir::Type r=matklad a=matklad
This introduces `hir::Type` wrapper over `hir::Ty`, with two purposes:
* bind `Ty` and it's corresponding environment
* Am I correct that `Ty` without an env doesn't make much sense, because the meaning of type parameters is unclear
* Am I correct that we can safely re-use the same environment for all types derived from the given type?
* hide representation defails of `Ty`. Specifically, I want to change `Ty::Adt` to use `hir_def::AdtId` instead of `hir::Adt`, but IDE doesn't know about underlying IDs. More generally, I feel like IDE shouldn't know that `Ty` is enum.
@flodiebold what do you think about this?
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/completion/complete_dot.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 5a3f9b5f6..b6fe48627 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -1,6 +1,6 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | 2 | ||
3 | use hir::{Adt, Ty, TypeCtor}; | 3 | use hir::Type; |
4 | 4 | ||
5 | use crate::completion::completion_item::CompletionKind; | 5 | use crate::completion::completion_item::CompletionKind; |
6 | use crate::{ | 6 | use crate::{ |
@@ -22,12 +22,12 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { | |||
22 | }; | 22 | }; |
23 | 23 | ||
24 | if !ctx.is_call { | 24 | if !ctx.is_call { |
25 | complete_fields(acc, ctx, receiver_ty.clone()); | 25 | complete_fields(acc, ctx, &receiver_ty); |
26 | } | 26 | } |
27 | complete_methods(acc, ctx, receiver_ty.clone()); | 27 | complete_methods(acc, ctx, &receiver_ty); |
28 | 28 | ||
29 | // Suggest .await syntax for types that implement Future trait | 29 | // Suggest .await syntax for types that implement Future trait |
30 | if ctx.analyzer.impls_future(ctx.db, receiver_ty) { | 30 | if ctx.analyzer.impls_future(ctx.db, receiver_ty.into_ty()) { |
31 | CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await") | 31 | CompletionItem::new(CompletionKind::Keyword, ctx.source_range(), "await") |
32 | .detail("expr.await") | 32 | .detail("expr.await") |
33 | .insert_text("await") | 33 | .insert_text("await") |
@@ -35,28 +35,18 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { | |||
35 | } | 35 | } |
36 | } | 36 | } |
37 | 37 | ||
38 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { | 38 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) { |
39 | for receiver in ctx.analyzer.autoderef(ctx.db, receiver) { | 39 | for receiver in receiver.autoderef(ctx.db) { |
40 | if let Ty::Apply(a_ty) = receiver { | 40 | for (field, ty) in receiver.fields(ctx.db) { |
41 | match a_ty.ctor { | 41 | acc.add_field(ctx, field, &ty); |
42 | TypeCtor::Adt(Adt::Struct(s)) => { | 42 | } |
43 | for field in s.fields(ctx.db) { | 43 | for (i, ty) in receiver.tuple_fields(ctx.db).into_iter().enumerate() { |
44 | acc.add_field(ctx, field, &a_ty.parameters); | 44 | acc.add_tuple_field(ctx, i, &ty); |
45 | } | 45 | } |
46 | } | ||
47 | // FIXME unions | ||
48 | TypeCtor::Tuple { .. } => { | ||
49 | for (i, ty) in a_ty.parameters.iter().enumerate() { | ||
50 | acc.add_tuple_field(ctx, i, ty); | ||
51 | } | ||
52 | } | ||
53 | _ => {} | ||
54 | } | ||
55 | }; | ||
56 | } | 46 | } |
57 | } | 47 | } |
58 | 48 | ||
59 | fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { | 49 | fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: &Type) { |
60 | let mut seen_methods = FxHashSet::default(); | 50 | let mut seen_methods = FxHashSet::default(); |
61 | ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| { | 51 | ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| { |
62 | if func.has_self_param(ctx.db) && seen_methods.insert(func.name(ctx.db)) { | 52 | if func.has_self_param(ctx.db) && seen_methods.insert(func.name(ctx.db)) { |