diff options
| author | Dorian Scheidt <dorian.scheidt@gmail.com> | 2022-08-02 12:11:32 -0400 |
|---|---|---|
| committer | Dorian Scheidt <dorian.scheidt@gmail.com> | 2022-08-02 14:37:12 -0400 |
| commit | 1980c1192c7bcfb10e1ed380ee90bcaa7153d58d (patch) | |
| tree | b3f0239668b4e9b1aa520e15f04cdc25485f5240 | |
| parent | 111694d85bc64e3604599668c5b2db574e07abf0 (diff) | |
| download | rust-1980c1192c7bcfb10e1ed380ee90bcaa7153d58d.tar.gz rust-1980c1192c7bcfb10e1ed380ee90bcaa7153d58d.zip | |
Support PathPat paths in generate_enum_variant
| -rw-r--r-- | crates/ide-assists/src/handlers/generate_enum_variant.rs | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/crates/ide-assists/src/handlers/generate_enum_variant.rs b/crates/ide-assists/src/handlers/generate_enum_variant.rs index b3dd29b7710..35cd42908af 100644 --- a/crates/ide-assists/src/handlers/generate_enum_variant.rs +++ b/crates/ide-assists/src/handlers/generate_enum_variant.rs @@ -60,6 +60,7 @@ pub(crate) fn generate_enum_variant(acc: &mut Assists, ctx: &AssistContext<'_>) enum PathParent { PathExpr(ast::PathExpr), RecordExpr(ast::RecordExpr), + PathPat(ast::PathPat), UseTree(ast::UseTree), } @@ -68,6 +69,7 @@ impl PathParent { match self { PathParent::PathExpr(it) => it.syntax(), PathParent::RecordExpr(it) => it.syntax(), + PathParent::PathPat(it) => it.syntax(), PathParent::UseTree(it) => it.syntax(), } } @@ -84,7 +86,7 @@ impl PathParent { } } PathParent::RecordExpr(it) => make_record_field_list(it, ctx, &scope), - PathParent::UseTree(_) => None, + PathParent::UseTree(_) | PathParent::PathPat(_) => None, } } } @@ -96,6 +98,7 @@ fn path_parent(path: &ast::Path) -> Option<PathParent> { match parent { ast::PathExpr(it) => Some(PathParent::PathExpr(it)), ast::RecordExpr(it) => Some(PathParent::RecordExpr(it)), + ast::PathPat(it) => Some(PathParent::PathPat(it)), ast::UseTree(it) => Some(PathParent::UseTree(it)), _ => None } @@ -533,4 +536,29 @@ impl Foo::Bar$0 {} ", ) } + + #[test] + fn path_pat() { + check_assist( + generate_enum_variant, + r" +enum Foo {} +fn foo(x: Foo) { + match x { + Foo::Bar$0 => + } +} +", + r" +enum Foo { + Bar, +} +fn foo(x: Foo) { + match x { + Foo::Bar => + } +} +", + ) + } } |
