diff options
author | Aleksey Kladov <[email protected]> | 2019-07-19 09:24:41 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-07-19 11:16:25 +0100 |
commit | 0343c4a815a0e82d5e55e76a01d21b0f7a00ff5b (patch) | |
tree | 126bafdfcbcb04741b87876d6204c449113d96b5 /crates/ra_assists/src/replace_if_let_with_match.rs | |
parent | e2b28f5bb8043e92b10f6a40696131007fc9dfe2 (diff) |
migrate ra_assists to the new AST
Diffstat (limited to 'crates/ra_assists/src/replace_if_let_with_match.rs')
-rw-r--r-- | crates/ra_assists/src/replace_if_let_with_match.rs | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/crates/ra_assists/src/replace_if_let_with_match.rs b/crates/ra_assists/src/replace_if_let_with_match.rs index c2c7cf70b..5de6aa266 100644 --- a/crates/ra_assists/src/replace_if_let_with_match.rs +++ b/crates/ra_assists/src/replace_if_let_with_match.rs | |||
@@ -5,7 +5,7 @@ use ra_syntax::{ast, AstNode}; | |||
5 | use crate::{Assist, AssistCtx, AssistId}; | 5 | use crate::{Assist, AssistCtx, AssistId}; |
6 | 6 | ||
7 | pub(crate) fn replace_if_let_with_match(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 7 | pub(crate) fn replace_if_let_with_match(mut ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
8 | let if_expr: &ast::IfExpr = ctx.node_at_offset()?; | 8 | let if_expr: ast::IfExpr = ctx.node_at_offset()?; |
9 | let cond = if_expr.condition()?; | 9 | let cond = if_expr.condition()?; |
10 | let pat = cond.pat()?; | 10 | let pat = cond.pat()?; |
11 | let expr = cond.expr()?; | 11 | let expr = cond.expr()?; |
@@ -25,16 +25,11 @@ pub(crate) fn replace_if_let_with_match(mut ctx: AssistCtx<impl HirDatabase>) -> | |||
25 | ctx.build() | 25 | ctx.build() |
26 | } | 26 | } |
27 | 27 | ||
28 | fn build_match_expr( | 28 | fn build_match_expr(expr: ast::Expr, pat1: ast::Pat, arm1: ast::Block, arm2: ast::Block) -> String { |
29 | expr: &ast::Expr, | ||
30 | pat1: &ast::Pat, | ||
31 | arm1: &ast::Block, | ||
32 | arm2: &ast::Block, | ||
33 | ) -> String { | ||
34 | let mut buf = String::new(); | 29 | let mut buf = String::new(); |
35 | buf.push_str(&format!("match {} {{\n", expr.syntax().text())); | 30 | buf.push_str(&format!("match {} {{\n", expr.syntax().text())); |
36 | buf.push_str(&format!(" {} => {}\n", pat1.syntax().text(), format_arm(arm1))); | 31 | buf.push_str(&format!(" {} => {}\n", pat1.syntax().text(), format_arm(&arm1))); |
37 | buf.push_str(&format!(" _ => {}\n", format_arm(arm2))); | 32 | buf.push_str(&format!(" _ => {}\n", format_arm(&arm2))); |
38 | buf.push_str("}"); | 33 | buf.push_str("}"); |
39 | buf | 34 | buf |
40 | } | 35 | } |