diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-21 13:06:00 +0100 |
---|---|---|
committer | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-07-21 13:06:00 +0100 |
commit | 1137fc47bbbc8d648db3bc669e41fd059a09dd1d (patch) | |
tree | 8d0e74c6c5a734fc64edf2504aabfd11c09354c4 /crates/ra_ide_api/src/completion/complete_struct_literal.rs | |
parent | 7bde8012cb28c44de7ffc779003781d385323808 (diff) | |
parent | 5fe19d2fbd2daa05b2cd3b1ebb6fa926e9d86c36 (diff) |
Merge #1572
1572: Provide completion in struct patterns r=matklad a=viorina
Co-authored-by: Ekaterina Babshukova <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src/completion/complete_struct_literal.rs')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_struct_literal.rs | 15 |
1 files changed, 7 insertions, 8 deletions
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 9410f740f..6aa41f498 100644 --- a/crates/ra_ide_api/src/completion/complete_struct_literal.rs +++ b/crates/ra_ide_api/src/completion/complete_struct_literal.rs | |||
@@ -1,23 +1,22 @@ | |||
1 | use hir::{Substs, Ty}; | 1 | use hir::Substs; |
2 | 2 | ||
3 | use crate::completion::{CompletionContext, Completions}; | 3 | use crate::completion::{CompletionContext, Completions}; |
4 | 4 | ||
5 | /// Complete fields in fields literals. | 5 | /// Complete fields in fields literals. |
6 | pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) { | 6 | pub(super) fn complete_struct_literal(acc: &mut Completions, ctx: &CompletionContext) { |
7 | let (ty, variant) = match ctx.struct_lit_syntax.as_ref().and_then(|it| { | 7 | let (ty, variant) = match ctx.struct_lit_syntax.as_ref().and_then(|it| { |
8 | Some((ctx.analyzer.type_of(ctx.db, &it.clone().into())?, ctx.analyzer.resolve_variant(it)?)) | 8 | Some(( |
9 | ctx.analyzer.type_of(ctx.db, &it.clone().into())?, | ||
10 | ctx.analyzer.resolve_struct_literal(it)?, | ||
11 | )) | ||
9 | }) { | 12 | }) { |
10 | Some(it) => it, | 13 | Some(it) => it, |
11 | _ => return, | 14 | _ => return, |
12 | }; | 15 | }; |
13 | 16 | let substs = &ty.substs().unwrap_or_else(Substs::empty); | |
14 | let ty_substs = match ty { | ||
15 | Ty::Apply(it) => it.parameters, | ||
16 | _ => Substs::empty(), | ||
17 | }; | ||
18 | 17 | ||
19 | for field in variant.fields(ctx.db) { | 18 | for field in variant.fields(ctx.db) { |
20 | acc.add_field(ctx, field, &ty_substs); | 19 | acc.add_field(ctx, field, substs); |
21 | } | 20 | } |
22 | } | 21 | } |
23 | 22 | ||