feat: bump variant suggestion for enums in patterns completion

This commit is contained in:
feniljain 2022-12-12 16:48:55 +05:30
parent e0aa5afd7b
commit 68fd1ce313
2 changed files with 14 additions and 3 deletions

View File

@ -496,6 +496,7 @@ pub(crate) fn add_variant_pat(
variant, variant,
local_name.clone(), local_name.clone(),
None, None,
false,
)); ));
} }
@ -514,6 +515,7 @@ pub(crate) fn add_qualified_variant_pat(
variant, variant,
None, None,
path, path,
true,
)); ));
} }

View File

@ -7,6 +7,7 @@
use crate::{ use crate::{
context::{ParamContext, ParamKind, PathCompletionCtx, PatternContext}, context::{ParamContext, ParamKind, PathCompletionCtx, PatternContext},
item::CompletionRelevanceTypeMatch,
render::{ render::{
variant::{format_literal_label, format_literal_lookup, visible_fields}, variant::{format_literal_label, format_literal_lookup, visible_fields},
RenderContext, RenderContext,
@ -37,7 +38,7 @@ pub(crate) fn render_struct_pat(
let lookup = format_literal_lookup(name.as_str(), kind); let lookup = format_literal_lookup(name.as_str(), kind);
let pat = render_pat(&ctx, pattern_ctx, &escaped_name, kind, &visible_fields, fields_omitted)?; let pat = render_pat(&ctx, pattern_ctx, &escaped_name, kind, &visible_fields, fields_omitted)?;
Some(build_completion(ctx, label, lookup, pat, strukt)) Some(build_completion(ctx, label, lookup, pat, strukt, false))
} }
pub(crate) fn render_variant_pat( pub(crate) fn render_variant_pat(
@ -47,6 +48,7 @@ pub(crate) fn render_variant_pat(
variant: hir::Variant, variant: hir::Variant,
local_name: Option<Name>, local_name: Option<Name>,
path: Option<&hir::ModPath>, path: Option<&hir::ModPath>,
is_exact_type_match: bool,
) -> Option<CompletionItem> { ) -> Option<CompletionItem> {
let _p = profile::span("render_variant_pat"); let _p = profile::span("render_variant_pat");
@ -81,7 +83,7 @@ pub(crate) fn render_variant_pat(
} }
}; };
Some(build_completion(ctx, label, lookup, pat, variant)) Some(build_completion(ctx, label, lookup, pat, variant, is_exact_type_match))
} }
fn build_completion( fn build_completion(
@ -90,13 +92,20 @@ fn build_completion(
lookup: SmolStr, lookup: SmolStr,
pat: String, pat: String,
def: impl HasAttrs + Copy, def: impl HasAttrs + Copy,
is_exact_type_match: bool,
) -> CompletionItem { ) -> CompletionItem {
let mut relevance = ctx.completion_relevance();
if is_exact_type_match {
relevance.type_match = Some(CompletionRelevanceTypeMatch::Exact);
}
let mut item = CompletionItem::new(CompletionItemKind::Binding, ctx.source_range(), label); let mut item = CompletionItem::new(CompletionItemKind::Binding, ctx.source_range(), label);
item.set_documentation(ctx.docs(def)) item.set_documentation(ctx.docs(def))
.set_deprecated(ctx.is_deprecated(def)) .set_deprecated(ctx.is_deprecated(def))
.detail(&pat) .detail(&pat)
.lookup_by(lookup) .lookup_by(lookup)
.set_relevance(ctx.completion_relevance()); .set_relevance(relevance);
match ctx.snippet_cap() { match ctx.snippet_cap() {
Some(snippet_cap) => item.insert_snippet(snippet_cap, pat), Some(snippet_cap) => item.insert_snippet(snippet_cap, pat),
None => item.insert_text(pat), None => item.insert_text(pat),