aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/libeditor/src/typing.rs5
-rw-r--r--crates/libeditor/tests/test.rs9
-rw-r--r--crates/libsyntax2/src/ast/generated.rs21
-rw-r--r--crates/libsyntax2/src/grammar.ron2
4 files changed, 34 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]
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs
index 6181aada8..b24fd2aba 100644
--- a/crates/libsyntax2/src/ast/generated.rs
+++ b/crates/libsyntax2/src/ast/generated.rs
@@ -339,6 +339,7 @@ pub enum Expr<'a> {
339 PrefixExpr(PrefixExpr<'a>), 339 PrefixExpr(PrefixExpr<'a>),
340 RangeExpr(RangeExpr<'a>), 340 RangeExpr(RangeExpr<'a>),
341 BinExpr(BinExpr<'a>), 341 BinExpr(BinExpr<'a>),
342 Literal(Literal<'a>),
342} 343}
343 344
344impl<'a> AstNode<'a> for Expr<'a> { 345impl<'a> AstNode<'a> for Expr<'a> {
@@ -375,6 +376,7 @@ impl<'a> AstNode<'a> for Expr<'a> {
375 PREFIX_EXPR => Some(Expr::PrefixExpr(PrefixExpr { syntax })), 376 PREFIX_EXPR => Some(Expr::PrefixExpr(PrefixExpr { syntax })),
376 RANGE_EXPR => Some(Expr::RangeExpr(RangeExpr { syntax })), 377 RANGE_EXPR => Some(Expr::RangeExpr(RangeExpr { syntax })),
377 BIN_EXPR => Some(Expr::BinExpr(BinExpr { syntax })), 378 BIN_EXPR => Some(Expr::BinExpr(BinExpr { syntax })),
379 LITERAL => Some(Expr::Literal(Literal { syntax })),
378 _ => None, 380 _ => None,
379 } 381 }
380 } 382 }
@@ -411,6 +413,7 @@ impl<'a> AstNode<'a> for Expr<'a> {
411 Expr::PrefixExpr(inner) => inner.syntax(), 413 Expr::PrefixExpr(inner) => inner.syntax(),
412 Expr::RangeExpr(inner) => inner.syntax(), 414 Expr::RangeExpr(inner) => inner.syntax(),
413 Expr::BinExpr(inner) => inner.syntax(), 415 Expr::BinExpr(inner) => inner.syntax(),
416 Expr::Literal(inner) => inner.syntax(),
414 } 417 }
415 } 418 }
416} 419}
@@ -726,6 +729,24 @@ impl<'a> LetStmt<'a> {
726 } 729 }
727} 730}
728 731
732// Literal
733#[derive(Debug, Clone, Copy)]
734pub struct Literal<'a> {
735 syntax: SyntaxNodeRef<'a>,
736}
737
738impl<'a> AstNode<'a> for Literal<'a> {
739 fn cast(syntax: SyntaxNodeRef<'a>) -> Option<Self> {
740 match syntax.kind() {
741 LITERAL => Some(Literal { syntax }),
742 _ => None,
743 }
744 }
745 fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax }
746}
747
748impl<'a> Literal<'a> {}
749
729// LoopExpr 750// LoopExpr
730#[derive(Debug, Clone, Copy)] 751#[derive(Debug, Clone, Copy)]
731pub struct LoopExpr<'a> { 752pub struct LoopExpr<'a> {
diff --git a/crates/libsyntax2/src/grammar.ron b/crates/libsyntax2/src/grammar.ron
index 7217a4633..c3a29c10c 100644
--- a/crates/libsyntax2/src/grammar.ron
+++ b/crates/libsyntax2/src/grammar.ron
@@ -384,6 +384,7 @@ Grammar(
384 "PrefixExpr": (), 384 "PrefixExpr": (),
385 "RangeExpr": (), 385 "RangeExpr": (),
386 "BinExpr": (), 386 "BinExpr": (),
387 "Literal": (),
387 388
388 "Expr": ( 389 "Expr": (
389 enum: [ 390 enum: [
@@ -418,6 +419,7 @@ Grammar(
418 "PrefixExpr", 419 "PrefixExpr",
419 "RangeExpr", 420 "RangeExpr",
420 "BinExpr", 421 "BinExpr",
422 "Literal",
421 ], 423 ],
422 ), 424 ),
423 425