From 6c41a205a908eb94f139f968f803e728fc3418c6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 28 Aug 2018 14:21:37 +0300 Subject: join any block --- crates/libeditor/src/typing.rs | 5 ++--- crates/libeditor/tests/test.rs | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'crates/libeditor') diff --git a/crates/libeditor/src/typing.rs b/crates/libeditor/src/typing.rs index 3a3776c26..daa57983f 100644 --- a/crates/libeditor/src/typing.rs +++ b/crates/libeditor/src/typing.rs @@ -84,7 +84,7 @@ fn remove_newline( offset: TextUnit, ) { if node.kind() == WHITESPACE && node_text.bytes().filter(|&b| b == b'\n').count() == 1 { - if join_lambda_body(edit, node).is_some() { + if join_single_expr_block(edit, node).is_some() { return } match (node.prev_sibling(), node.next_sibling()) { @@ -118,13 +118,12 @@ fn remove_newline( ); } -fn join_lambda_body( +fn join_single_expr_block( edit: &mut EditBuilder, node: SyntaxNodeRef, ) -> Option<()> { let block = ast::Block::cast(node.parent()?)?; let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?; - let _lambda = ast::LambdaExpr::cast(block_expr.syntax().parent()?)?; let expr = single_expr(block)?; edit.replace( block_expr.syntax().range(), diff --git a/crates/libeditor/tests/test.rs b/crates/libeditor/tests/test.rs index 2be54215a..440afe92d 100644 --- a/crates/libeditor/tests/test.rs +++ b/crates/libeditor/tests/test.rs @@ -222,6 +222,15 @@ pub fn reparse(&self, edit: &AtomEdit) -> File { <|>self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit)) } "); + do_check(r" +fn foo() { + foo(<|>{ + 92 + }) +}", r" +fn foo() { + foo(<|>92) +}"); } #[test] -- cgit v1.2.3