diff options
author | Lukas Wirth <[email protected]> | 2020-12-05 14:41:36 +0000 |
---|---|---|
committer | Lukas Wirth <[email protected]> | 2020-12-05 14:41:36 +0000 |
commit | 44c76d6550081552c3c5106b0535a7e5bf265aec (patch) | |
tree | 362d0555ac4b8a4b41a06b2ffada92a17b758ae7 /crates/syntax | |
parent | a3043cf53feffef3f69f25c2617801d2fc66ce75 (diff) |
Add replace_match_with_if_let assist
Diffstat (limited to 'crates/syntax')
-rw-r--r-- | crates/syntax/src/ast/make.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/crates/syntax/src/ast/make.rs b/crates/syntax/src/ast/make.rs index 876659a2b..cc09b77a5 100644 --- a/crates/syntax/src/ast/make.rs +++ b/crates/syntax/src/ast/make.rs | |||
@@ -171,8 +171,17 @@ pub fn expr_return() -> ast::Expr { | |||
171 | pub fn expr_match(expr: ast::Expr, match_arm_list: ast::MatchArmList) -> ast::Expr { | 171 | pub fn expr_match(expr: ast::Expr, match_arm_list: ast::MatchArmList) -> ast::Expr { |
172 | expr_from_text(&format!("match {} {}", expr, match_arm_list)) | 172 | expr_from_text(&format!("match {} {}", expr, match_arm_list)) |
173 | } | 173 | } |
174 | pub fn expr_if(condition: ast::Condition, then_branch: ast::BlockExpr) -> ast::Expr { | 174 | pub fn expr_if( |
175 | expr_from_text(&format!("if {} {}", condition, then_branch)) | 175 | condition: ast::Condition, |
176 | then_branch: ast::BlockExpr, | ||
177 | else_branch: Option<ast::ElseBranch>, | ||
178 | ) -> ast::Expr { | ||
179 | let else_branch = match else_branch { | ||
180 | Some(ast::ElseBranch::Block(block)) => format!("else {}", block), | ||
181 | Some(ast::ElseBranch::IfExpr(if_expr)) => format!("else {}", if_expr), | ||
182 | None => String::new(), | ||
183 | }; | ||
184 | expr_from_text(&format!("if {} {} {}", condition, then_branch, else_branch)) | ||
176 | } | 185 | } |
177 | pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr { | 186 | pub fn expr_prefix(op: SyntaxKind, expr: ast::Expr) -> ast::Expr { |
178 | let token = token(op); | 187 | let token = token(op); |