feat: do not remove other variants, just push them down in list
This commit is contained in:
parent
d03c789798
commit
6778d1a6eb
@ -536,7 +536,6 @@ fn enum_variants_with_paths(
|
||||
enum_: hir::Enum,
|
||||
impl_: &Option<ast::Impl>,
|
||||
cb: impl Fn(&mut Completions, &CompletionContext<'_>, hir::Variant, hir::ModPath),
|
||||
missing_variants: Option<Vec<Variant>>,
|
||||
) {
|
||||
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_)) {
|
||||
|
@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -32,11 +32,22 @@ pub(crate) struct RenderContext<'a> {
|
||||
completion: &'a CompletionContext<'a>,
|
||||
is_private_editable: bool,
|
||||
import_to_add: Option<LocatedImport>,
|
||||
// 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<bool>,
|
||||
}
|
||||
|
||||
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 {
|
||||
|
@ -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();
|
||||
|
||||
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))
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user