diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-10 13:07:19 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-01-10 13:07:19 +0000 |
commit | aca14c591fea40b2f803bbf5f02c1571732348fb (patch) | |
tree | 432f3cac863a499fe573cd747a2f7ca2d65b70c8 /crates/ra_ide_api/src/completion/complete_dot.rs | |
parent | aef93c918e2b6e0b8826e970b00c46f8a5c3aaa9 (diff) | |
parent | 56b2138d82620db946fe08ddc164c5e7e22be625 (diff) |
Merge #475
475: Show types of fields in completion r=matklad a=matklad
![image](https://user-images.githubusercontent.com/1711539/50910524-0f146200-143f-11e9-84d6-0ba80761cd89.png)
r? @flodiebold
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 | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 5d4e60dc5..65bba6dc7 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs | |||
@@ -28,13 +28,13 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) | |||
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 | for field in s.fields(ctx.db)? { |
32 | for field in variant_data.fields() { | ||
33 | CompletionItem::new( | 32 | CompletionItem::new( |
34 | CompletionKind::Reference, | 33 | CompletionKind::Reference, |
35 | field.name().to_string(), | 34 | field.name().to_string(), |
36 | ) | 35 | ) |
37 | .kind(CompletionItemKind::Field) | 36 | .kind(CompletionItemKind::Field) |
37 | .set_detail(field.ty(ctx.db)?.map(|ty| ty.to_string())) | ||
38 | .add_to(acc); | 38 | .add_to(acc); |
39 | } | 39 | } |
40 | } | 40 | } |
@@ -72,7 +72,7 @@ mod tests { | |||
72 | a.<|> | 72 | a.<|> |
73 | } | 73 | } |
74 | ", | 74 | ", |
75 | r#"the_field"#, | 75 | r#"the_field "u32""#, |
76 | ); | 76 | ); |
77 | } | 77 | } |
78 | 78 | ||
@@ -80,14 +80,14 @@ mod tests { | |||
80 | fn test_struct_field_completion_self() { | 80 | fn test_struct_field_completion_self() { |
81 | check_ref_completion( | 81 | check_ref_completion( |
82 | r" | 82 | r" |
83 | struct A { the_field: u32 } | 83 | struct A { the_field: (u32,) } |
84 | impl A { | 84 | impl A { |
85 | fn foo(self) { | 85 | fn foo(self) { |
86 | self.<|> | 86 | self.<|> |
87 | } | 87 | } |
88 | } | 88 | } |
89 | ", | 89 | ", |
90 | r#"the_field"#, | 90 | r#"the_field "(u32,)""#, |
91 | ); | 91 | ); |
92 | } | 92 | } |
93 | 93 | ||
@@ -95,14 +95,14 @@ mod tests { | |||
95 | fn test_struct_field_completion_autoderef() { | 95 | fn test_struct_field_completion_autoderef() { |
96 | check_ref_completion( | 96 | check_ref_completion( |
97 | r" | 97 | r" |
98 | struct A { the_field: u32 } | 98 | struct A { the_field: (u32, i32) } |
99 | impl A { | 99 | impl A { |
100 | fn foo(&self) { | 100 | fn foo(&self) { |
101 | self.<|> | 101 | self.<|> |
102 | } | 102 | } |
103 | } | 103 | } |
104 | ", | 104 | ", |
105 | r#"the_field"#, | 105 | r#"the_field "(u32, i32)""#, |
106 | ); | 106 | ); |
107 | } | 107 | } |
108 | 108 | ||