mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 22:31:43 +00:00
Show enum variant completions for ref scrutinee
This commit is contained in:
parent
943e4faceb
commit
15a52f69d9
1 changed files with 26 additions and 1 deletions
|
@ -1,5 +1,7 @@
|
||||||
//! Completion of names from the current scope, e.g. locals and imported items.
|
//! Completion of names from the current scope, e.g. locals and imported items.
|
||||||
|
|
||||||
|
use std::iter;
|
||||||
|
|
||||||
use either::Either;
|
use either::Either;
|
||||||
use hir::{Adt, ModPath, ModuleDef, ScopeDef, Type};
|
use hir::{Adt, ModPath, ModuleDef, ScopeDef, Type};
|
||||||
use ide_db::helpers::insert_use::ImportScope;
|
use ide_db::helpers::insert_use::ImportScope;
|
||||||
|
@ -50,7 +52,9 @@ pub(crate) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionC
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &Type) {
|
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 variants = enum_data.variants(ctx.db);
|
||||||
|
|
||||||
let module = if let Some(module) = ctx.scope.module() {
|
let module = if let Some(module) = ctx.scope.module() {
|
||||||
|
@ -701,6 +705,7 @@ fn main() { <|> }
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn completes_enum_variant_matcharm() {
|
fn completes_enum_variant_matcharm() {
|
||||||
check(
|
check(
|
||||||
|
@ -721,6 +726,26 @@ fn main() {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[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]
|
#[test]
|
||||||
fn completes_enum_variant_iflet() {
|
fn completes_enum_variant_iflet() {
|
||||||
check(
|
check(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue