diff options
Diffstat (limited to 'crates/ra_ide_api/src/completion')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 27 | ||||
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_struct_literal.rs | 6 |
2 files changed, 15 insertions, 18 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 94c66be31..dc5206a64 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use hir::{Ty, AdtDef}; | 1 | use hir::{Ty, AdtDef, TypeName}; |
2 | 2 | ||
3 | use crate::completion::{CompletionContext, Completions}; | 3 | use crate::completion::{CompletionContext, Completions}; |
4 | 4 | ||
@@ -24,23 +24,20 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) { | |||
24 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { | 24 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { |
25 | for receiver in receiver.autoderef(ctx.db) { | 25 | for receiver in receiver.autoderef(ctx.db) { |
26 | match receiver { | 26 | match receiver { |
27 | Ty::Adt { def_id, ref substs, .. } => { | 27 | Ty::Apply(a_ty) => match a_ty.name { |
28 | match def_id { | 28 | TypeName::Adt(AdtDef::Struct(s)) => { |
29 | AdtDef::Struct(s) => { | 29 | for field in s.fields(ctx.db) { |
30 | for field in s.fields(ctx.db) { | 30 | acc.add_field(ctx, field, &a_ty.parameters); |
31 | acc.add_field(ctx, field, substs); | ||
32 | } | ||
33 | } | 31 | } |
34 | |||
35 | // TODO unions | ||
36 | AdtDef::Enum(_) => (), | ||
37 | } | 32 | } |
38 | } | 33 | // TODO unions |
39 | Ty::Tuple(fields) => { | 34 | TypeName::Tuple => { |
40 | for (i, ty) in fields.iter().enumerate() { | 35 | for (i, ty) in a_ty.parameters.iter().enumerate() { |
41 | acc.add_pos_field(ctx, i, ty); | 36 | acc.add_pos_field(ctx, i, ty); |
37 | } | ||
42 | } | 38 | } |
43 | } | 39 | _ => {} |
40 | }, | ||
44 | _ => {} | 41 | _ => {} |
45 | }; | 42 | }; |
46 | } | 43 | } |
diff --git a/crates/ra_ide_api/src/completion/complete_struct_literal.rs b/crates/ra_ide_api/src/completion/complete_struct_literal.rs index 6bef9624e..b75526282 100644 --- a/crates/ra_ide_api/src/completion/complete_struct_literal.rs +++ b/crates/ra_ide_api/src/completion/complete_struct_literal.rs | |||
@@ -1,4 +1,4 @@ | |||
1 | use hir::{Ty, AdtDef}; | 1 | use hir::AdtDef; |
2 | 2 | ||
3 | use crate::completion::{CompletionContext, Completions}; | 3 | use crate::completion::{CompletionContext, Completions}; |
4 | 4 | ||
@@ -15,8 +15,8 @@ pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionCon | |||
15 | None => return, | 15 | None => return, |
16 | }; | 16 | }; |
17 | let ty = infer_result[expr].clone(); | 17 | let ty = infer_result[expr].clone(); |
18 | let (adt, substs) = match ty { | 18 | let (adt, substs) = match ty.as_adt() { |
19 | Ty::Adt { def_id, ref substs, .. } => (def_id, substs), | 19 | Some(res) => res, |
20 | _ => return, | 20 | _ => return, |
21 | }; | 21 | }; |
22 | match adt { | 22 | match adt { |