diff --git a/crates/ide-completion/src/completions.rs b/crates/ide-completion/src/completions.rs index ec8a23e907c..50be5c788fb 100644 --- a/crates/ide-completion/src/completions.rs +++ b/crates/ide-completion/src/completions.rs @@ -536,7 +536,6 @@ fn enum_variants_with_paths( enum_: hir::Enum, impl_: &Option, cb: impl Fn(&mut Completions, &CompletionContext<'_>, hir::Variant, hir::ModPath), - missing_variants: Option>, ) { let mut process_variant = |variant: Variant| { let self_path = hir::ModPath::from_segments( @@ -547,10 +546,7 @@ fn enum_variants_with_paths( cb(acc, ctx, variant, self_path); }; - let variants = match missing_variants { - Some(missing_variants) => missing_variants, - None => enum_.variants(ctx.db), - }; + let variants = enum_.variants(ctx.db); if let Some(impl_) = impl_.as_ref().and_then(|impl_| ctx.sema.to_def(impl_)) { if impl_.self_ty(ctx.db).as_adt() == Some(hir::Adt::Enum(enum_)) { diff --git a/crates/ide-completion/src/completions/expr.rs b/crates/ide-completion/src/completions/expr.rs index 8946011280a..3192b21cfb2 100644 --- a/crates/ide-completion/src/completions/expr.rs +++ b/crates/ide-completion/src/completions/expr.rs @@ -208,7 +208,6 @@ pub(crate) fn complete_expr_path( |acc, ctx, variant, path| { acc.add_qualified_enum_variant(ctx, path_ctx, variant, path) }, - None, ); } } diff --git a/crates/ide-completion/src/completions/pattern.rs b/crates/ide-completion/src/completions/pattern.rs index 6ad6a06f11a..58d5bf114cc 100644 --- a/crates/ide-completion/src/completions/pattern.rs +++ b/crates/ide-completion/src/completions/pattern.rs @@ -58,7 +58,6 @@ pub(crate) fn complete_pattern( |acc, ctx, variant, path| { acc.add_qualified_variant_pat(ctx, pattern_ctx, variant, path); }, - Some(pattern_ctx.missing_variants.clone()), ); } } diff --git a/crates/ide-completion/src/render.rs b/crates/ide-completion/src/render.rs index 86302cb0678..eb2df395c4d 100644 --- a/crates/ide-completion/src/render.rs +++ b/crates/ide-completion/src/render.rs @@ -32,11 +32,22 @@ pub(crate) struct RenderContext<'a> { completion: &'a CompletionContext<'a>, is_private_editable: bool, import_to_add: Option, + // For variants which are missing + // in match completion context + // + // Option -> only applicable for enums + // bool -> is enum variant missing or not? + is_variant_missing: Option, } impl<'a> RenderContext<'a> { pub(crate) fn new(completion: &'a CompletionContext<'a>) -> RenderContext<'a> { - RenderContext { completion, is_private_editable: false, import_to_add: None } + RenderContext { + completion, + is_private_editable: false, + import_to_add: None, + is_variant_missing: None, + } } pub(crate) fn private_editable(mut self, private_editable: bool) -> Self { diff --git a/crates/ide-completion/src/render/pattern.rs b/crates/ide-completion/src/render/pattern.rs index 37c65abba93..d70f02127d5 100644 --- a/crates/ide-completion/src/render/pattern.rs +++ b/crates/ide-completion/src/render/pattern.rs @@ -43,7 +43,7 @@ pub(crate) fn render_struct_pat( } pub(crate) fn render_variant_pat( - ctx: RenderContext<'_>, + mut ctx: RenderContext<'_>, pattern_ctx: &PatternContext, path_ctx: Option<&PathCompletionCtx>, variant: hir::Variant, @@ -56,6 +56,11 @@ pub(crate) fn render_variant_pat( let (visible_fields, fields_omitted) = visible_fields(ctx.completion, &fields, variant)?; let enum_ty = variant.parent_enum(ctx.db()).ty(ctx.db()); + // Missing in context of match statement completions + if pattern_ctx.missing_variants.contains(&variant) { + ctx.is_variant_missing = Some(true); + } + let (name, escaped_name) = match path { Some(path) => (path.unescaped().to_string().into(), path.to_string().into()), None => { @@ -97,7 +102,9 @@ fn build_completion( ) -> CompletionItem { let mut relevance = ctx.completion_relevance(); - relevance.type_match = super::compute_type_match(ctx.completion, &adt_ty); + if let Some(true) = ctx.is_variant_missing { + relevance.type_match = super::compute_type_match(ctx.completion, &adt_ty); + } let mut item = CompletionItem::new(CompletionItemKind::Binding, ctx.source_range(), label); item.set_documentation(ctx.docs(def)) diff --git a/crates/ide-completion/src/tests/record.rs b/crates/ide-completion/src/tests/record.rs index 727114610e7..2de42e8435e 100644 --- a/crates/ide-completion/src/tests/record.rs +++ b/crates/ide-completion/src/tests/record.rs @@ -67,6 +67,7 @@ fn foo(baz: Baz) { ev Err ev Ok bn Baz::Bar Baz::Bar$0 + bn Baz::Foo Baz::Foo$0 bn Err(…) Err($1)$0 bn Ok(…) Ok($1)$0 kw mut @@ -93,6 +94,7 @@ fn foo(baz: Baz) { ev Err ev Ok bn Baz::Bar Baz::Bar$0 + bn Baz::Foo Baz::Foo$0 bn Err(…) Err($1)$0 bn Ok(…) Ok($1)$0 kw mut