@@ -60,36 +60,15 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU
60
60
return ;
61
61
}
62
62
63
- // Special case that turns something like:
64
- //
65
- // ```
66
- // my_function({<|>
67
- // <some-expr>
68
- // })
69
- // ```
70
- //
71
- // into `my_function(<some-expr>)`
72
- if join_single_expr_block ( edit, token) . is_some ( ) {
73
- return ;
74
- }
75
- // ditto for
76
- //
77
- // ```
78
- // use foo::{<|>
79
- // bar
80
- // };
81
- // ```
82
- if join_single_use_tree ( edit, token) . is_some ( ) {
83
- return ;
84
- }
85
-
86
63
// The node is between two other nodes
87
64
let prev = token. prev_sibling_or_token ( ) . unwrap ( ) ;
88
65
let next = token. next_sibling_or_token ( ) . unwrap ( ) ;
89
66
if is_trailing_comma ( prev. kind ( ) , next. kind ( ) ) {
90
67
// Removes: trailing comma, newline (incl. surrounding whitespace)
91
68
edit. delete ( TextRange :: from_to ( prev. text_range ( ) . start ( ) , token. text_range ( ) . end ( ) ) ) ;
92
- } else if prev. kind ( ) == T ! [ , ] && next. kind ( ) == T ! [ '}' ] {
69
+ return ;
70
+ }
71
+ if prev. kind ( ) == T ! [ , ] && next. kind ( ) == T ! [ '}' ] {
93
72
// Removes: comma, newline (incl. surrounding whitespace)
94
73
let space = if let Some ( left) = prev. prev_sibling_or_token ( ) {
95
74
compute_ws ( left. kind ( ) , next. kind ( ) )
@@ -100,7 +79,10 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU
100
79
TextRange :: from_to ( prev. text_range ( ) . start ( ) , token. text_range ( ) . end ( ) ) ,
101
80
space. to_string ( ) ,
102
81
) ;
103
- } else if let ( Some ( _) , Some ( next) ) = (
82
+ return ;
83
+ }
84
+
85
+ if let ( Some ( _) , Some ( next) ) = (
104
86
prev. as_token ( ) . cloned ( ) . and_then ( ast:: Comment :: cast) ,
105
87
next. as_token ( ) . cloned ( ) . and_then ( ast:: Comment :: cast) ,
106
88
) {
@@ -109,10 +91,34 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU
109
91
token. text_range ( ) . start ( ) ,
110
92
next. syntax ( ) . text_range ( ) . start ( ) + TextUnit :: of_str ( next. prefix ( ) ) ,
111
93
) ) ;
112
- } else {
113
- // Remove newline but add a computed amount of whitespace characters
114
- edit. replace ( token. text_range ( ) , compute_ws ( prev. kind ( ) , next. kind ( ) ) . to_string ( ) ) ;
94
+ return ;
95
+ }
96
+
97
+ // Special case that turns something like:
98
+ //
99
+ // ```
100
+ // my_function({<|>
101
+ // <some-expr>
102
+ // })
103
+ // ```
104
+ //
105
+ // into `my_function(<some-expr>)`
106
+ if join_single_expr_block ( edit, token) . is_some ( ) {
107
+ return ;
115
108
}
109
+ // ditto for
110
+ //
111
+ // ```
112
+ // use foo::{<|>
113
+ // bar
114
+ // };
115
+ // ```
116
+ if join_single_use_tree ( edit, token) . is_some ( ) {
117
+ return ;
118
+ }
119
+
120
+ // Remove newline but add a computed amount of whitespace characters
121
+ edit. replace ( token. text_range ( ) , compute_ws ( prev. kind ( ) , next. kind ( ) ) . to_string ( ) ) ;
116
122
}
117
123
118
124
fn has_comma_after ( node : & SyntaxNode ) -> bool {
@@ -608,4 +614,27 @@ pub fn handle_find_matching_brace() {
608
614
}" ,
609
615
) ;
610
616
}
617
+
618
+ #[ test]
619
+ fn test_join_lines_commented_block ( ) {
620
+ check_join_lines (
621
+ r"
622
+ fn main() {
623
+ let _ = {
624
+ // <|>foo
625
+ // bar
626
+ 92
627
+ };
628
+ }
629
+ " ,
630
+ r"
631
+ fn main() {
632
+ let _ = {
633
+ // <|>foo bar
634
+ 92
635
+ };
636
+ }
637
+ " ,
638
+ )
639
+ }
611
640
}
0 commit comments