diff options
author | Aleksey Kladov <[email protected]> | 2019-09-02 19:23:19 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-09-02 19:23:19 +0100 |
commit | 5e3f291195b580580be7ce5622f54ebca75fb9f0 (patch) | |
tree | 772693eb44bde1fac1b9292456e1fa6e056bdb1f /crates/ra_assists | |
parent | dcf8e895038a7677711b8168ee12e1d47f6018bc (diff) |
fix hir for new block syntax
Diffstat (limited to 'crates/ra_assists')
-rw-r--r-- | crates/ra_assists/src/move_guard.rs | 4 | ||||
-rw-r--r-- | crates/ra_assists/src/replace_if_let_with_match.rs | 16 |
2 files changed, 13 insertions, 7 deletions
diff --git a/crates/ra_assists/src/move_guard.rs b/crates/ra_assists/src/move_guard.rs index 127c9e068..699221e33 100644 --- a/crates/ra_assists/src/move_guard.rs +++ b/crates/ra_assists/src/move_guard.rs | |||
@@ -65,9 +65,9 @@ pub(crate) fn move_arm_cond_to_match_guard(mut ctx: AssistCtx<impl HirDatabase>) | |||
65 | "move condition to match guard", | 65 | "move condition to match guard", |
66 | |edit| { | 66 | |edit| { |
67 | edit.target(if_expr.syntax().text_range()); | 67 | edit.target(if_expr.syntax().text_range()); |
68 | let then_only_expr = then_block.statements().next().is_none(); | 68 | let then_only_expr = then_block.block().and_then(|it| it.statements().next()).is_none(); |
69 | 69 | ||
70 | match &then_block.expr() { | 70 | match &then_block.block().and_then(|it| it.expr()) { |
71 | Some(then_expr) if then_only_expr => { | 71 | Some(then_expr) if then_only_expr => { |
72 | edit.replace(if_expr.syntax().text_range(), then_expr.syntax().text()) | 72 | edit.replace(if_expr.syntax().text_range(), then_expr.syntax().text()) |
73 | } | 73 | } |
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 c0bf6d235..401835c57 100644 --- a/crates/ra_assists/src/replace_if_let_with_match.rs +++ b/crates/ra_assists/src/replace_if_let_with_match.rs | |||
@@ -1,3 +1,4 @@ | |||
1 | use format_buf::format; | ||
1 | use hir::db::HirDatabase; | 2 | use hir::db::HirDatabase; |
2 | use ra_fmt::extract_trivial_expression; | 3 | use ra_fmt::extract_trivial_expression; |
3 | use ra_syntax::{ast, AstNode}; | 4 | use ra_syntax::{ast, AstNode}; |
@@ -25,16 +26,21 @@ pub(crate) fn replace_if_let_with_match(mut ctx: AssistCtx<impl HirDatabase>) -> | |||
25 | ctx.build() | 26 | ctx.build() |
26 | } | 27 | } |
27 | 28 | ||
28 | fn build_match_expr(expr: ast::Expr, pat1: ast::Pat, arm1: ast::Block, arm2: ast::Block) -> String { | 29 | fn build_match_expr( |
30 | expr: ast::Expr, | ||
31 | pat1: ast::Pat, | ||
32 | arm1: ast::BlockExpr, | ||
33 | arm2: ast::BlockExpr, | ||
34 | ) -> String { | ||
29 | let mut buf = String::new(); | 35 | let mut buf = String::new(); |
30 | buf.push_str(&format!("match {} {{\n", expr.syntax().text())); | 36 | format!(buf, "match {} {{\n", expr.syntax().text()); |
31 | buf.push_str(&format!(" {} => {}\n", pat1.syntax().text(), format_arm(&arm1))); | 37 | format!(buf, " {} => {}\n", pat1.syntax().text(), format_arm(&arm1)); |
32 | buf.push_str(&format!(" _ => {}\n", format_arm(&arm2))); | 38 | format!(buf, " _ => {}\n", format_arm(&arm2)); |
33 | buf.push_str("}"); | 39 | buf.push_str("}"); |
34 | buf | 40 | buf |
35 | } | 41 | } |
36 | 42 | ||
37 | fn format_arm(block: &ast::Block) -> String { | 43 | fn format_arm(block: &ast::BlockExpr) -> String { |
38 | match extract_trivial_expression(block) { | 44 | match extract_trivial_expression(block) { |
39 | None => block.syntax().text().to_string(), | 45 | None => block.syntax().text().to_string(), |
40 | Some(e) => format!("{},", e.syntax().text()), | 46 | Some(e) => format!("{},", e.syntax().text()), |