Skip to content

Commit 15a52f6

Browse files
committed
Show enum variant completions for ref scrutinee
1 parent 943e4fa commit 15a52f6

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

crates/completion/src/completions/unqualified_path.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Completion of names from the current scope, e.g. locals and imported items.
22
3+
use std::iter;
4+
35
use either::Either;
46
use hir::{Adt, ModPath, ModuleDef, ScopeDef, Type};
57
use ide_db::helpers::insert_use::ImportScope;
@@ -50,7 +52,9 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
5052
}
5153

5254
fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &Type) {
53-
if let Some(Adt::Enum(enum_data)) = ty.as_adt() {
55+
if let Some(Adt::Enum(enum_data)) =
56+
iter::successors(Some(ty.clone()), |ty| ty.remove_ref()).last().and_then(|ty| ty.as_adt())
57+
{
5458
let variants = enum_data.variants(ctx.db);
5559

5660
let module = if let Some(module) = ctx.scope.module() {
@@ -701,6 +705,7 @@ fn main() { <|> }
701705
"#]],
702706
);
703707
}
708+
704709
#[test]
705710
fn completes_enum_variant_matcharm() {
706711
check(
@@ -721,6 +726,26 @@ fn main() {
721726
)
722727
}
723728

729+
#[test]
730+
fn completes_enum_variant_matcharm_ref() {
731+
check(
732+
r#"
733+
enum Foo { Bar, Baz, Quux }
734+
735+
fn main() {
736+
let foo = Foo::Quux;
737+
match &foo { Qu<|> }
738+
}
739+
"#,
740+
expect![[r#"
741+
ev Foo::Bar ()
742+
ev Foo::Baz ()
743+
ev Foo::Quux ()
744+
en Foo
745+
"#]],
746+
)
747+
}
748+
724749
#[test]
725750
fn completes_enum_variant_iflet() {
726751
check(

0 commit comments

Comments
 (0)