Unnamed repository; edit this file 'description' to name the repository.
-rw-r--r--crates/ide-assists/src/handlers/generate_enum_variant.rs30
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 b3dd29b771..35cd42908a 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 =>
+ }
+}
+",
+ )
+ }
}