@@ -52,13 +52,17 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
5252 | PathResolution :: Def ( def @ hir:: ModuleDef :: TypeAlias ( _) )
5353 | PathResolution :: Def ( def @ hir:: ModuleDef :: BuiltinType ( _) ) => {
5454 if let hir:: ModuleDef :: Adt ( Adt :: Enum ( e) ) = def {
55- for variant in e. variants ( ctx. db ) {
56- acc. add_enum_variant ( ctx, variant, None ) ;
57- }
55+ add_enum_variants ( ctx, acc, e) ;
5856 }
5957 let ty = match def {
6058 hir:: ModuleDef :: Adt ( adt) => adt. ty ( ctx. db ) ,
61- hir:: ModuleDef :: TypeAlias ( a) => a. ty ( ctx. db ) ,
59+ hir:: ModuleDef :: TypeAlias ( a) => {
60+ let ty = a. ty ( ctx. db ) ;
61+ if let Some ( Adt :: Enum ( e) ) = ty. as_adt ( ) {
62+ add_enum_variants ( ctx, acc, e) ;
63+ }
64+ ty
65+ }
6266 hir:: ModuleDef :: BuiltinType ( builtin) => {
6367 let module = match ctx. scope . module ( ) {
6468 Some ( it) => it,
@@ -122,9 +126,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
122126 } ;
123127
124128 if let Some ( Adt :: Enum ( e) ) = ty. as_adt ( ) {
125- for variant in e. variants ( ctx. db ) {
126- acc. add_enum_variant ( ctx, variant, None ) ;
127- }
129+ add_enum_variants ( ctx, acc, e) ;
128130 }
129131
130132 let traits_in_scope = ctx. scope . traits_in_scope ( ) ;
@@ -151,6 +153,12 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
151153 }
152154}
153155
156+ fn add_enum_variants ( ctx : & CompletionContext , acc : & mut Completions , e : hir:: Enum ) {
157+ for variant in e. variants ( ctx. db ) {
158+ acc. add_enum_variant ( ctx, variant, None ) ;
159+ }
160+ }
161+
154162#[ cfg( test) ]
155163mod tests {
156164 use expect_test:: { expect, Expect } ;
@@ -782,4 +790,22 @@ impl u8 {
782790 "# ] ] ,
783791 ) ;
784792 }
793+
794+ #[ test]
795+ fn completes_through_alias ( ) {
796+ check (
797+ r#"
798+ enum Foo {
799+ Bar
800+ }
801+ type Foo2 = Foo;
802+ fn main() {
803+ Foo2::$0
804+ }
805+ "# ,
806+ expect ! [ [ r#"
807+ ev Bar ()
808+ "# ] ] ,
809+ ) ;
810+ }
785811}
0 commit comments