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