diff options
author | Aleksey Kladov <[email protected]> | 2020-02-05 09:50:07 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2020-02-05 13:08:16 +0000 |
commit | a4c6e8c4e22ddea9668eb3380603ad53d8ce6a5e (patch) | |
tree | 24f302e769cd8d2e27b6ab7a39b2df1376b65660 /crates/ra_fmt/src | |
parent | 83dc22e1fb4ff4897d911c18884259823edb68ba (diff) |
Refactor if-let -> match assist to use ast::make
Diffstat (limited to 'crates/ra_fmt/src')
-rw-r--r-- | crates/ra_fmt/src/lib.rs | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/crates/ra_fmt/src/lib.rs b/crates/ra_fmt/src/lib.rs index 10f592257..4bca27b5c 100644 --- a/crates/ra_fmt/src/lib.rs +++ b/crates/ra_fmt/src/lib.rs | |||
@@ -35,8 +35,14 @@ fn prev_tokens(token: SyntaxToken) -> impl Iterator<Item = SyntaxToken> { | |||
35 | successors(token.prev_token(), |token| token.prev_token()) | 35 | successors(token.prev_token(), |token| token.prev_token()) |
36 | } | 36 | } |
37 | 37 | ||
38 | pub fn extract_trivial_expression(expr: &ast::BlockExpr) -> Option<ast::Expr> { | 38 | pub fn unwrap_trivial_block(block: ast::BlockExpr) -> ast::Expr { |
39 | let block = expr.block()?; | 39 | extract_trivial_expression(&block) |
40 | .filter(|expr| !expr.syntax().text().contains_char('\n')) | ||
41 | .unwrap_or_else(|| block.into()) | ||
42 | } | ||
43 | |||
44 | pub fn extract_trivial_expression(block: &ast::BlockExpr) -> Option<ast::Expr> { | ||
45 | let block = block.block()?; | ||
40 | let expr = block.expr()?; | 46 | let expr = block.expr()?; |
41 | let non_trivial_children = block.syntax().children().filter(|it| match it.kind() { | 47 | let non_trivial_children = block.syntax().children().filter(|it| match it.kind() { |
42 | WHITESPACE | T!['{'] | T!['}'] => false, | 48 | WHITESPACE | T!['{'] | T!['}'] => false, |