aboutsummaryrefslogtreecommitdiff
path: root/crates/ide_completion/src
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ide_completion/src')
-rw-r--r--crates/ide_completion/src/completions/qualified_path.rs40
1 files changed, 33 insertions, 7 deletions
diff --git a/crates/ide_completion/src/completions/qualified_path.rs b/crates/ide_completion/src/completions/qualified_path.rs
index d8f23d1eb..d2ebba65f 100644
--- a/crates/ide_completion/src/completions/qualified_path.rs
+++ b/crates/ide_completion/src/completions/qualified_path.rs
@@ -52,13 +52,17 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
52 | PathResolution::Def(def @ hir::ModuleDef::TypeAlias(_)) 52 | PathResolution::Def(def @ hir::ModuleDef::TypeAlias(_))
53 | PathResolution::Def(def @ hir::ModuleDef::BuiltinType(_)) => { 53 | PathResolution::Def(def @ hir::ModuleDef::BuiltinType(_)) => {
54 if let hir::ModuleDef::Adt(Adt::Enum(e)) = def { 54 if let hir::ModuleDef::Adt(Adt::Enum(e)) = def {
55 for variant in e.variants(ctx.db) { 55 add_enum_variants(ctx, acc, e);
56 acc.add_enum_variant(ctx, variant, None);
57 }
58 } 56 }
59 let ty = match def { 57 let ty = match def {
60 hir::ModuleDef::Adt(adt) => adt.ty(ctx.db), 58 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 }
62 hir::ModuleDef::BuiltinType(builtin) => { 66 hir::ModuleDef::BuiltinType(builtin) => {
63 let module = match ctx.scope.module() { 67 let module = match ctx.scope.module() {
64 Some(it) => it, 68 Some(it) => it,
@@ -122,9 +126,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
122 }; 126 };
123 127
124 if let Some(Adt::Enum(e)) = ty.as_adt() { 128 if let Some(Adt::Enum(e)) = ty.as_adt() {
125 for variant in e.variants(ctx.db) { 129 add_enum_variants(ctx, acc, e);
126 acc.add_enum_variant(ctx, variant, None);
127 }
128 } 130 }
129 131
130 let traits_in_scope = ctx.scope.traits_in_scope(); 132 let traits_in_scope = ctx.scope.traits_in_scope();
@@ -151,6 +153,12 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
151 } 153 }
152} 154}
153 155
156fn 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
154#[cfg(test)] 162#[cfg(test)]
155mod tests { 163mod tests {
156 use expect_test::{expect, Expect}; 164 use expect_test::{expect, Expect};
@@ -782,4 +790,22 @@ impl u8 {
782 "#]], 790 "#]],
783 ); 791 );
784 } 792 }
793
794 #[test]
795 fn completes_through_alias() {
796 check(
797 r#"
798enum Foo {
799 Bar
800}
801type Foo2 = Foo;
802fn main() {
803 Foo2::$0
804}
805"#,
806 expect![[r#"
807 ev Bar ()
808 "#]],
809 );
810 }
785} 811}