Skip to content

Commit a10372d

Browse files
committed
fix: use compute_type_match correctly and update tests accordingly
1 parent 794988c commit a10372d

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

crates/ide-completion/src/completions.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,6 @@ impl Completions {
496496
variant,
497497
local_name.clone(),
498498
None,
499-
false,
500499
));
501500
}
502501

@@ -515,7 +514,6 @@ impl Completions {
515514
variant,
516515
None,
517516
path,
518-
true,
519517
));
520518
}
521519

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use syntax::SmolStr;
77

88
use crate::{
99
context::{ParamContext, ParamKind, PathCompletionCtx, PatternContext},
10-
item::CompletionRelevanceTypeMatch,
1110
render::{
1211
variant::{format_literal_label, format_literal_lookup, visible_fields},
1312
RenderContext,
@@ -38,7 +37,9 @@ pub(crate) fn render_struct_pat(
3837
let lookup = format_literal_lookup(name.as_str(), kind);
3938
let pat = render_pat(&ctx, pattern_ctx, &escaped_name, kind, &visible_fields, fields_omitted)?;
4039

41-
Some(build_completion(ctx, label, lookup, pat, strukt, true))
40+
let db = ctx.db();
41+
42+
Some(build_completion(ctx, label, lookup, pat, strukt, strukt.ty(db)))
4243
}
4344

4445
pub(crate) fn render_variant_pat(
@@ -48,12 +49,12 @@ pub(crate) fn render_variant_pat(
4849
variant: hir::Variant,
4950
local_name: Option<Name>,
5051
path: Option<&hir::ModPath>,
51-
is_exact_type_match: bool,
5252
) -> Option<CompletionItem> {
5353
let _p = profile::span("render_variant_pat");
5454

5555
let fields = variant.fields(ctx.db());
5656
let (visible_fields, fields_omitted) = visible_fields(ctx.completion, &fields, variant)?;
57+
let enum_ty = variant.parent_enum(ctx.db()).ty(ctx.db());
5758

5859
let (name, escaped_name) = match path {
5960
Some(path) => (path.unescaped().to_string().into(), path.to_string().into()),
@@ -83,7 +84,7 @@ pub(crate) fn render_variant_pat(
8384
}
8485
};
8586

86-
Some(build_completion(ctx, label, lookup, pat, variant, is_exact_type_match))
87+
Some(build_completion(ctx, label, lookup, pat, variant, enum_ty))
8788
}
8889

8990
fn build_completion(
@@ -92,13 +93,11 @@ fn build_completion(
9293
lookup: SmolStr,
9394
pat: String,
9495
def: impl HasAttrs + Copy,
95-
is_exact_type_match: bool,
96+
adt_ty: hir::Type,
9697
) -> CompletionItem {
9798
let mut relevance = ctx.completion_relevance();
9899

99-
if is_exact_type_match {
100-
relevance.type_match = Some(CompletionRelevanceTypeMatch::Exact);
101-
}
100+
relevance.type_match = super::compute_type_match(ctx.completion, &adt_ty);
102101

103102
let mut item = CompletionItem::new(CompletionItemKind::Binding, ctx.source_range(), label);
104103
item.set_documentation(ctx.docs(def))

crates/ide-completion/src/tests/record.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ fn foo(s: Struct) {
5050
fn record_pattern_field_enum() {
5151
check(
5252
r#"
53+
//- minicore:result
5354
enum Baz { FOO, BAR }
5455
5556
fn foo(baz: Baz) {
@@ -61,14 +62,21 @@ fn foo(baz: Baz) {
6162
"#,
6263
expect![[r#"
6364
en Baz
65+
en Result
66+
md core
67+
ev Err
68+
ev Ok
6469
bn Baz::BAR Baz::BAR$0
70+
bn Err(…) Err($1)$0
71+
bn Ok(…) Ok($1)$0
6572
kw mut
6673
kw ref
6774
"#]],
6875
);
6976

7077
check(
7178
r#"
79+
//- minicore:result
7280
enum Baz { FOO, BAR }
7381
7482
fn foo(baz: Baz) {
@@ -77,13 +85,19 @@ fn foo(baz: Baz) {
7785
$0
7886
}
7987
}
80-
"#,
88+
"#,
8189
expect![[r#"
82-
en Baz
83-
bn Baz::BAR Baz::BAR$0
84-
kw mut
85-
kw ref
86-
"#]],
90+
en Baz
91+
en Result
92+
md core
93+
ev Err
94+
ev Ok
95+
bn Baz::BAR Baz::BAR$0
96+
bn Err(…) Err($1)$0
97+
bn Ok(…) Ok($1)$0
98+
kw mut
99+
kw ref
100+
"#]],
87101
);
88102
}
89103

0 commit comments

Comments
 (0)