diff options
Diffstat (limited to 'crates/ra_ide/src/join_lines.rs')
-rw-r--r-- | crates/ra_ide/src/join_lines.rs | 69 |
1 files changed, 67 insertions, 2 deletions
diff --git a/crates/ra_ide/src/join_lines.rs b/crates/ra_ide/src/join_lines.rs index fde0bfa98..63fd6b3e4 100644 --- a/crates/ra_ide/src/join_lines.rs +++ b/crates/ra_ide/src/join_lines.rs | |||
@@ -129,8 +129,10 @@ fn has_comma_after(node: &SyntaxNode) -> bool { | |||
129 | } | 129 | } |
130 | 130 | ||
131 | fn join_single_expr_block(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Option<()> { | 131 | fn join_single_expr_block(edit: &mut TextEditBuilder, token: &SyntaxToken) -> Option<()> { |
132 | let block = ast::Block::cast(token.parent())?; | 132 | let block_expr = ast::BlockExpr::cast(token.parent())?; |
133 | let block_expr = ast::BlockExpr::cast(block.syntax().parent()?)?; | 133 | if !block_expr.is_standalone() { |
134 | return None; | ||
135 | } | ||
134 | let expr = extract_trivial_expression(&block_expr)?; | 136 | let expr = extract_trivial_expression(&block_expr)?; |
135 | 137 | ||
136 | let block_range = block_expr.syntax().text_range(); | 138 | let block_range = block_expr.syntax().text_range(); |
@@ -662,4 +664,67 @@ fn main() { | |||
662 | ", | 664 | ", |
663 | ) | 665 | ) |
664 | } | 666 | } |
667 | |||
668 | #[test] | ||
669 | fn join_lines_mandatory_blocks_block() { | ||
670 | check_join_lines( | ||
671 | r" | ||
672 | <|>fn foo() { | ||
673 | 92 | ||
674 | } | ||
675 | ", | ||
676 | r" | ||
677 | <|>fn foo() { 92 | ||
678 | } | ||
679 | ", | ||
680 | ); | ||
681 | |||
682 | check_join_lines( | ||
683 | r" | ||
684 | fn foo() { | ||
685 | <|>if true { | ||
686 | 92 | ||
687 | } | ||
688 | } | ||
689 | ", | ||
690 | r" | ||
691 | fn foo() { | ||
692 | <|>if true { 92 | ||
693 | } | ||
694 | } | ||
695 | ", | ||
696 | ); | ||
697 | |||
698 | check_join_lines( | ||
699 | r" | ||
700 | fn foo() { | ||
701 | <|>loop { | ||
702 | 92 | ||
703 | } | ||
704 | } | ||
705 | ", | ||
706 | r" | ||
707 | fn foo() { | ||
708 | <|>loop { 92 | ||
709 | } | ||
710 | } | ||
711 | ", | ||
712 | ); | ||
713 | |||
714 | check_join_lines( | ||
715 | r" | ||
716 | fn foo() { | ||
717 | <|>unsafe { | ||
718 | 92 | ||
719 | } | ||
720 | } | ||
721 | ", | ||
722 | r" | ||
723 | fn foo() { | ||
724 | <|>unsafe { 92 | ||
725 | } | ||
726 | } | ||
727 | ", | ||
728 | ); | ||
729 | } | ||
665 | } | 730 | } |