aboutsummaryrefslogtreecommitdiff
path: root/crates/libeditor
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-28 12:21:37 +0100
committerAleksey Kladov <[email protected]>2018-08-28 12:21:37 +0100
commit6c41a205a908eb94f139f968f803e728fc3418c6 (patch)
treea57ecdabdb29151a05c8b6be3e06009f464e2941 /crates/libeditor
parent288c9d1ac625c4fa451bdb8ff54830fb9f9795e0 (diff)
join any block
Diffstat (limited to 'crates/libeditor')
-rw-r--r--crates/libeditor/src/typing.rs5
-rw-r--r--crates/libeditor/tests/test.rs9
2 files changed, 11 insertions, 3 deletions
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(
84 offset: TextUnit, 84 offset: TextUnit,
85) { 85) {
86 if node.kind() == WHITESPACE && node_text.bytes().filter(|&b| b == b'\n').count() == 1 { 86 if node.kind() == WHITESPACE && node_text.bytes().filter(|&b| b == b'\n').count() == 1 {
87 if join_lambda_body(edit, node).is_some() { 87 if join_single_expr_block(edit, node).is_some() {
88 return 88 return
89 } 89 }
90 match (node.prev_sibling(), node.next_sibling()) { 90 match (node.prev_sibling(), node.next_sibling()) {
@@ -118,13 +118,12 @@ fn remove_newline(
118 ); 118 );
119} 119}
120 120
121fn join_lambda_body( 121fn join_single_expr_block(
122 edit: &mut EditBuilder, 122 edit: &mut EditBuilder,
123 node: SyntaxNodeRef, 123 node: SyntaxNodeRef,
124) -> Option<()> { 124) -> Option<()> {
125 let block = ast::Block::cast(node.parent()?)?; 125 let block = ast::Block::cast(node.parent()?)?;
126 let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?; 126 let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?;
127 let _lambda = ast::LambdaExpr::cast(block_expr.syntax().parent()?)?;
128 let expr = single_expr(block)?; 127 let expr = single_expr(block)?;
129 edit.replace( 128 edit.replace(
130 block_expr.syntax().range(), 129 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 {
222 <|>self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit)) 222 <|>self.incremental_reparse(edit).unwrap_or_else(|| self.full_reparse(edit))
223} 223}
224"); 224");
225 do_check(r"
226fn foo() {
227 foo(<|>{
228 92
229 })
230}", r"
231fn foo() {
232 foo(<|>92)
233}");
225} 234}
226 235
227#[test] 236#[test]