//! Completion of names from the current scope, e.g. locals and imported items.
+use std::iter;
+
use either::Either;
use hir::{Adt, ModPath, ModuleDef, ScopeDef, Type};
use ide_db::helpers::insert_use::ImportScope;
}
fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &Type) {
- if let Some(Adt::Enum(enum_data)) = ty.as_adt() {
+ if let Some(Adt::Enum(enum_data)) =
+ iter::successors(Some(ty.clone()), |ty| ty.remove_ref()).last().and_then(|ty| ty.as_adt())
+ {
let variants = enum_data.variants(ctx.db);
let module = if let Some(module) = ctx.scope.module() {
"#]],
);
}
+
#[test]
fn completes_enum_variant_matcharm() {
check(
)
}
+ #[test]
+ fn completes_enum_variant_matcharm_ref() {
+ check(
+ r#"
+enum Foo { Bar, Baz, Quux }
+
+fn main() {
+ let foo = Foo::Quux;
+ match &foo { Qu<|> }
+}
+"#,
+ expect![[r#"
+ ev Foo::Bar ()
+ ev Foo::Baz ()
+ ev Foo::Quux ()
+ en Foo
+ "#]],
+ )
+ }
+
#[test]
fn completes_enum_variant_iflet() {
check(