Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions crates/ide_completion/src/completions/qualified_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,17 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
| PathResolution::Def(def @ hir::ModuleDef::TypeAlias(_))
| PathResolution::Def(def @ hir::ModuleDef::BuiltinType(_)) => {
if let hir::ModuleDef::Adt(Adt::Enum(e)) = def {
for variant in e.variants(ctx.db) {
acc.add_enum_variant(ctx, variant, None);
}
add_enum_variants(ctx, acc, e);
}
let ty = match def {
hir::ModuleDef::Adt(adt) => adt.ty(ctx.db),
hir::ModuleDef::TypeAlias(a) => a.ty(ctx.db),
hir::ModuleDef::TypeAlias(a) => {
let ty = a.ty(ctx.db);
if let Some(Adt::Enum(e)) = ty.as_adt() {
Copy link
Member

@lnicola lnicola May 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Umm, doesn't this also happen below? Or maybe not. Sorry, I was reading the diff on my phone.

add_enum_variants(ctx, acc, e);
}
ty
}
hir::ModuleDef::BuiltinType(builtin) => {
let module = match ctx.scope.module() {
Some(it) => it,
Expand Down Expand Up @@ -122,9 +126,7 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
};

if let Some(Adt::Enum(e)) = ty.as_adt() {
for variant in e.variants(ctx.db) {
acc.add_enum_variant(ctx, variant, None);
}
add_enum_variants(ctx, acc, e);
}

let traits_in_scope = ctx.scope.traits_in_scope();
Expand All @@ -151,6 +153,12 @@ pub(crate) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon
}
}

fn add_enum_variants(ctx: &CompletionContext, acc: &mut Completions, e: hir::Enum) {
for variant in e.variants(ctx.db) {
acc.add_enum_variant(ctx, variant, None);
}
}

#[cfg(test)]
mod tests {
use expect_test::{expect, Expect};
Expand Down Expand Up @@ -782,4 +790,22 @@ impl u8 {
"#]],
);
}

#[test]
fn completes_through_alias() {
check(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cov_mark

r#"
enum Foo {
Bar
}
type Foo2 = Foo;
fn main() {
Foo2::$0
}
"#,
expect![[r#"
ev Bar ()
"#]],
);
}
}