Skip to content

Commit a79a76a

Browse files
committed
refactor: pass is_variant_missing as args to build_completion
1 parent f711368 commit a79a76a

File tree

2 files changed

+15
-21
lines changed

2 files changed

+15
-21
lines changed

crates/ide-completion/src/render.rs

+1-12
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,11 @@ pub(crate) struct RenderContext<'a> {
3232
completion: &'a CompletionContext<'a>,
3333
is_private_editable: bool,
3434
import_to_add: Option<LocatedImport>,
35-
// For variants which are missing
36-
// in match completion context
37-
//
38-
// Option -> only applicable for enums
39-
// bool -> is enum variant missing or not?
40-
is_variant_missing: Option<bool>,
4135
}
4236

4337
impl<'a> RenderContext<'a> {
4438
pub(crate) fn new(completion: &'a CompletionContext<'a>) -> RenderContext<'a> {
45-
RenderContext {
46-
completion,
47-
is_private_editable: false,
48-
import_to_add: None,
49-
is_variant_missing: None,
50-
}
39+
RenderContext { completion, is_private_editable: false, import_to_add: None }
5140
}
5241

5342
pub(crate) fn private_editable(mut self, private_editable: bool) -> Self {

crates/ide-completion/src/render/pattern.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ pub(crate) fn render_struct_pat(
3939

4040
let db = ctx.db();
4141

42-
Some(build_completion(ctx, label, lookup, pat, strukt, strukt.ty(db)))
42+
Some(build_completion(ctx, label, lookup, pat, strukt, strukt.ty(db), false))
4343
}
4444

4545
pub(crate) fn render_variant_pat(
46-
mut ctx: RenderContext<'_>,
46+
ctx: RenderContext<'_>,
4747
pattern_ctx: &PatternContext,
4848
path_ctx: Option<&PathCompletionCtx>,
4949
variant: hir::Variant,
@@ -56,11 +56,6 @@ pub(crate) fn render_variant_pat(
5656
let (visible_fields, fields_omitted) = visible_fields(ctx.completion, &fields, variant)?;
5757
let enum_ty = variant.parent_enum(ctx.db()).ty(ctx.db());
5858

59-
// Missing in context of match statement completions
60-
if pattern_ctx.missing_variants.contains(&variant) {
61-
ctx.is_variant_missing = Some(true);
62-
}
63-
6459
let (name, escaped_name) = match path {
6560
Some(path) => (path.unescaped().to_string().into(), path.to_string().into()),
6661
None => {
@@ -89,7 +84,15 @@ pub(crate) fn render_variant_pat(
8984
}
9085
};
9186

92-
Some(build_completion(ctx, label, lookup, pat, variant, enum_ty))
87+
Some(build_completion(
88+
ctx,
89+
label,
90+
lookup,
91+
pat,
92+
variant,
93+
enum_ty,
94+
pattern_ctx.missing_variants.contains(&variant),
95+
))
9396
}
9497

9598
fn build_completion(
@@ -99,10 +102,12 @@ fn build_completion(
99102
pat: String,
100103
def: impl HasAttrs + Copy,
101104
adt_ty: hir::Type,
105+
// Missing in context of match statement completions
106+
is_variant_missing: bool,
102107
) -> CompletionItem {
103108
let mut relevance = ctx.completion_relevance();
104109

105-
if let Some(true) = ctx.is_variant_missing {
110+
if is_variant_missing {
106111
relevance.type_match = super::compute_type_match(ctx.completion, &adt_ty);
107112
}
108113

0 commit comments

Comments
 (0)