diff options
Diffstat (limited to 'crates/ra_analysis/src/completion/complete_dot.rs')
-rw-r--r-- | crates/ra_analysis/src/completion/complete_dot.rs | 57 |
1 files changed, 38 insertions, 19 deletions
diff --git a/crates/ra_analysis/src/completion/complete_dot.rs b/crates/ra_analysis/src/completion/complete_dot.rs index 54ce1b638..5d4e60dc5 100644 --- a/crates/ra_analysis/src/completion/complete_dot.rs +++ b/crates/ra_analysis/src/completion/complete_dot.rs | |||
@@ -23,31 +23,35 @@ pub(super) fn complete_dot(acc: &mut Completions, ctx: &CompletionContext) -> Ca | |||
23 | } | 23 | } |
24 | 24 | ||
25 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) -> Cancelable<()> { | 25 | fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) -> Cancelable<()> { |
26 | // TODO: autoderef etc. | 26 | for receiver in receiver.autoderef(ctx.db) { |
27 | match receiver { | 27 | match receiver { |
28 | Ty::Adt { def_id, .. } => { | 28 | Ty::Adt { def_id, .. } => { |
29 | match def_id.resolve(ctx.db)? { | 29 | match def_id.resolve(ctx.db)? { |
30 | Def::Struct(s) => { | 30 | Def::Struct(s) => { |
31 | let variant_data = s.variant_data(ctx.db)?; | 31 | let variant_data = s.variant_data(ctx.db)?; |
32 | for field in variant_data.fields() { | 32 | for field in variant_data.fields() { |
33 | CompletionItem::new(CompletionKind::Reference, field.name().to_string()) | 33 | CompletionItem::new( |
34 | CompletionKind::Reference, | ||
35 | field.name().to_string(), | ||
36 | ) | ||
34 | .kind(CompletionItemKind::Field) | 37 | .kind(CompletionItemKind::Field) |
35 | .add_to(acc); | 38 | .add_to(acc); |
39 | } | ||
36 | } | 40 | } |
41 | // TODO unions | ||
42 | _ => {} | ||
37 | } | 43 | } |
38 | // TODO unions | ||
39 | _ => {} | ||
40 | } | 44 | } |
41 | } | 45 | Ty::Tuple(fields) => { |
42 | Ty::Tuple(fields) => { | 46 | for (i, _ty) in fields.iter().enumerate() { |
43 | for (i, _ty) in fields.iter().enumerate() { | 47 | CompletionItem::new(CompletionKind::Reference, i.to_string()) |
44 | CompletionItem::new(CompletionKind::Reference, i.to_string()) | 48 | .kind(CompletionItemKind::Field) |
45 | .kind(CompletionItemKind::Field) | 49 | .add_to(acc); |
46 | .add_to(acc); | 50 | } |
47 | } | 51 | } |
48 | } | 52 | _ => {} |
49 | _ => {} | 53 | }; |
50 | }; | 54 | } |
51 | Ok(()) | 55 | Ok(()) |
52 | } | 56 | } |
53 | 57 | ||
@@ -88,6 +92,21 @@ mod tests { | |||
88 | } | 92 | } |
89 | 93 | ||
90 | #[test] | 94 | #[test] |
95 | fn test_struct_field_completion_autoderef() { | ||
96 | check_ref_completion( | ||
97 | r" | ||
98 | struct A { the_field: u32 } | ||
99 | impl A { | ||
100 | fn foo(&self) { | ||
101 | self.<|> | ||
102 | } | ||
103 | } | ||
104 | ", | ||
105 | r#"the_field"#, | ||
106 | ); | ||
107 | } | ||
108 | |||
109 | #[test] | ||
91 | fn test_no_struct_field_completion_for_method_call() { | 110 | fn test_no_struct_field_completion_for_method_call() { |
92 | check_ref_completion( | 111 | check_ref_completion( |
93 | r" | 112 | r" |