diff options
Diffstat (limited to 'crates/ra_assists/src/assists/fill_match_arms.rs')
-rw-r--r-- | crates/ra_assists/src/assists/fill_match_arms.rs | 25 |
1 files changed, 11 insertions, 14 deletions
diff --git a/crates/ra_assists/src/assists/fill_match_arms.rs b/crates/ra_assists/src/assists/fill_match_arms.rs index f1c36b805..817433526 100644 --- a/crates/ra_assists/src/assists/fill_match_arms.rs +++ b/crates/ra_assists/src/assists/fill_match_arms.rs | |||
@@ -3,7 +3,7 @@ use std::iter; | |||
3 | use hir::{db::HirDatabase, Adt, HasSource}; | 3 | use hir::{db::HirDatabase, Adt, HasSource}; |
4 | use ra_syntax::ast::{self, AstNode, NameOwner}; | 4 | use ra_syntax::ast::{self, AstNode, NameOwner}; |
5 | 5 | ||
6 | use crate::{ast_builder::AstBuilder, Assist, AssistCtx, AssistId}; | 6 | use crate::{ast_builder::Make, Assist, AssistCtx, AssistId}; |
7 | 7 | ||
8 | pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 8 | pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
9 | let match_expr = ctx.node_at_offset::<ast::MatchExpr>()?; | 9 | let match_expr = ctx.node_at_offset::<ast::MatchExpr>()?; |
@@ -29,13 +29,10 @@ pub(crate) fn fill_match_arms(mut ctx: AssistCtx<impl HirDatabase>) -> Option<As | |||
29 | 29 | ||
30 | ctx.add_action(AssistId("fill_match_arms"), "fill match arms", |edit| { | 30 | ctx.add_action(AssistId("fill_match_arms"), "fill match arms", |edit| { |
31 | let variants = variant_list.variants(); | 31 | let variants = variant_list.variants(); |
32 | let arms = variants.filter_map(build_pat).map(|pat| { | 32 | let arms = variants |
33 | AstBuilder::<ast::MatchArm>::from_pieces( | 33 | .filter_map(build_pat) |
34 | iter::once(pat), | 34 | .map(|pat| Make::<ast::MatchArm>::from(iter::once(pat), Make::<ast::Expr>::unit())); |
35 | AstBuilder::<ast::Expr>::unit(), | 35 | let new_arm_list = Make::<ast::MatchArmList>::from_arms(arms); |
36 | ) | ||
37 | }); | ||
38 | let new_arm_list = AstBuilder::<ast::MatchArmList>::from_arms(arms); | ||
39 | 36 | ||
40 | edit.target(match_expr.syntax().text_range()); | 37 | edit.target(match_expr.syntax().text_range()); |
41 | edit.set_cursor(expr.syntax().text_range().start()); | 38 | edit.set_cursor(expr.syntax().text_range().start()); |
@@ -66,21 +63,21 @@ fn resolve_enum_def( | |||
66 | } | 63 | } |
67 | 64 | ||
68 | fn build_pat(var: ast::EnumVariant) -> Option<ast::Pat> { | 65 | fn build_pat(var: ast::EnumVariant) -> Option<ast::Pat> { |
69 | let path = AstBuilder::<ast::Path>::from_pieces(var.parent_enum().name()?, var.name()?); | 66 | let path = Make::<ast::Path>::from(var.parent_enum().name()?, var.name()?); |
70 | 67 | ||
71 | let pat: ast::Pat = match var.kind() { | 68 | let pat: ast::Pat = match var.kind() { |
72 | ast::StructKind::Tuple(field_list) => { | 69 | ast::StructKind::Tuple(field_list) => { |
73 | let pats = iter::repeat(AstBuilder::<ast::PlaceholderPat>::placeholder().into()) | 70 | let pats = iter::repeat(Make::<ast::PlaceholderPat>::placeholder().into()) |
74 | .take(field_list.fields().count()); | 71 | .take(field_list.fields().count()); |
75 | AstBuilder::<ast::TupleStructPat>::from_pieces(path, pats).into() | 72 | Make::<ast::TupleStructPat>::from(path, pats).into() |
76 | } | 73 | } |
77 | ast::StructKind::Named(field_list) => { | 74 | ast::StructKind::Named(field_list) => { |
78 | let pats = field_list | 75 | let pats = field_list |
79 | .fields() | 76 | .fields() |
80 | .map(|f| AstBuilder::<ast::BindPat>::from_name(f.name().unwrap()).into()); | 77 | .map(|f| Make::<ast::BindPat>::from_name(f.name().unwrap()).into()); |
81 | AstBuilder::<ast::RecordPat>::from_pieces(path, pats).into() | 78 | Make::<ast::RecordPat>::from(path, pats).into() |
82 | } | 79 | } |
83 | ast::StructKind::Unit => AstBuilder::<ast::PathPat>::from_path(path).into(), | 80 | ast::StructKind::Unit => Make::<ast::PathPat>::from_path(path).into(), |
84 | }; | 81 | }; |
85 | 82 | ||
86 | Some(pat) | 83 | Some(pat) |