Skip to content

Commit 68fd1ce

Browse files
committed
feat: bump variant suggestion for enums in patterns completion
1 parent e0aa5af commit 68fd1ce

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

crates/ide-completion/src/completions.rs

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

@@ -514,6 +515,7 @@ impl Completions {
514515
variant,
515516
None,
516517
path,
518+
true,
517519
));
518520
}
519521

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

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

88
use crate::{
99
context::{ParamContext, ParamKind, PathCompletionCtx, PatternContext},
10+
item::CompletionRelevanceTypeMatch,
1011
render::{
1112
variant::{format_literal_label, format_literal_lookup, visible_fields},
1213
RenderContext,
@@ -37,7 +38,7 @@ pub(crate) fn render_struct_pat(
3738
let lookup = format_literal_lookup(name.as_str(), kind);
3839
let pat = render_pat(&ctx, pattern_ctx, &escaped_name, kind, &visible_fields, fields_omitted)?;
3940

40-
Some(build_completion(ctx, label, lookup, pat, strukt))
41+
Some(build_completion(ctx, label, lookup, pat, strukt, false))
4142
}
4243

4344
pub(crate) fn render_variant_pat(
@@ -47,6 +48,7 @@ pub(crate) fn render_variant_pat(
4748
variant: hir::Variant,
4849
local_name: Option<Name>,
4950
path: Option<&hir::ModPath>,
51+
is_exact_type_match: bool,
5052
) -> Option<CompletionItem> {
5153
let _p = profile::span("render_variant_pat");
5254

@@ -81,7 +83,7 @@ pub(crate) fn render_variant_pat(
8183
}
8284
};
8385

84-
Some(build_completion(ctx, label, lookup, pat, variant))
86+
Some(build_completion(ctx, label, lookup, pat, variant, is_exact_type_match))
8587
}
8688

8789
fn build_completion(
@@ -90,13 +92,20 @@ fn build_completion(
9092
lookup: SmolStr,
9193
pat: String,
9294
def: impl HasAttrs + Copy,
95+
is_exact_type_match: bool,
9396
) -> CompletionItem {
97+
let mut relevance = ctx.completion_relevance();
98+
99+
if is_exact_type_match {
100+
relevance.type_match = Some(CompletionRelevanceTypeMatch::Exact);
101+
}
102+
94103
let mut item = CompletionItem::new(CompletionItemKind::Binding, ctx.source_range(), label);
95104
item.set_documentation(ctx.docs(def))
96105
.set_deprecated(ctx.is_deprecated(def))
97106
.detail(&pat)
98107
.lookup_by(lookup)
99-
.set_relevance(ctx.completion_relevance());
108+
.set_relevance(relevance);
100109
match ctx.snippet_cap() {
101110
Some(snippet_cap) => item.insert_snippet(snippet_cap, pat),
102111
None => item.insert_text(pat),

0 commit comments

Comments
 (0)