Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide-completion/src/completions/record.rs')
| -rw-r--r-- | crates/ide-completion/src/completions/record.rs | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/crates/ide-completion/src/completions/record.rs b/crates/ide-completion/src/completions/record.rs index 8cef3a7018..9f5922c5b0 100644 --- a/crates/ide-completion/src/completions/record.rs +++ b/crates/ide-completion/src/completions/record.rs @@ -17,6 +17,7 @@ pub(crate) fn complete_record_pattern_fields( complete_fields(acc, ctx, ctx.sema.record_pattern_missing_fields(record_pat)); } } + pub(crate) fn complete_record_expr_fields( acc: &mut Completions, ctx: &CompletionContext, @@ -41,7 +42,6 @@ pub(crate) fn complete_record_expr_fields( } _ => { let missing_fields = ctx.sema.record_literal_missing_fields(record_expr); - add_default_update(acc, ctx, ty, &missing_fields); if dot_prefix { let mut item = @@ -56,6 +56,29 @@ pub(crate) fn complete_record_expr_fields( complete_fields(acc, ctx, missing_fields); } +// FIXME: This should probably be part of complete_path_expr +pub(crate) fn complete_record_expr_func_update( + acc: &mut Completions, + ctx: &CompletionContext, + path_ctx: &PathCompletionCtx, + expr_ctx: &ExprCtx, +) { + if !matches!(path_ctx.qualified, Qualified::No) { + return; + } + if let ExprCtx { is_func_update: Some(record_expr), .. } = expr_ctx { + let ty = ctx.sema.type_of_expr(&Expr::RecordExpr(record_expr.clone())); + + match ty.as_ref().and_then(|t| t.original.as_adt()) { + Some(hir::Adt::Union(_)) => (), + _ => { + let missing_fields = ctx.sema.record_literal_missing_fields(record_expr); + add_default_update(acc, ctx, ty, &missing_fields); + } + }; + } +} + fn add_default_update( acc: &mut Completions, ctx: &CompletionContext, @@ -67,6 +90,7 @@ fn add_default_update( .zip(ty.as_ref()) .map_or(false, |(default_trait, ty)| ty.original.impls_trait(ctx.db, default_trait, &[])); if impl_default_trait && !missing_fields.is_empty() { + // FIXME: This should make use of scope_def like completions so we get all the other goodies let completion_text = "..Default::default()"; let mut item = CompletionItem::new(SymbolKind::Field, ctx.source_range(), completion_text); let completion_text = @@ -79,28 +103,6 @@ fn add_default_update( } } -pub(crate) fn complete_record_expr_func_update( - acc: &mut Completions, - ctx: &CompletionContext, - path_ctx: &PathCompletionCtx, - expr_ctx: &ExprCtx, -) { - if !matches!(path_ctx.qualified, Qualified::No) { - return; - } - if let ExprCtx { is_func_update: Some(record_expr), .. } = expr_ctx { - let ty = ctx.sema.type_of_expr(&Expr::RecordExpr(record_expr.clone())); - - match ty.as_ref().and_then(|t| t.original.as_adt()) { - Some(hir::Adt::Union(_)) => (), - _ => { - let missing_fields = ctx.sema.record_literal_missing_fields(record_expr); - add_default_update(acc, ctx, ty, &missing_fields); - } - }; - } -} - fn complete_fields( acc: &mut Completions, ctx: &CompletionContext, |