Skip to content

Commit adfed5c

Browse files
committed
Fix join lines when two rules match
1 parent 305d921 commit adfed5c

File tree

1 file changed

+46
-23
lines changed

1 file changed

+46
-23
lines changed

crates/ra_ide/src/join_lines.rs

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,29 +60,6 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU
6060
return;
6161
}
6262

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-
8663
// The node is between two other nodes
8764
let prev = token.prev_sibling_or_token().unwrap();
8865
let next = token.next_sibling_or_token().unwrap();
@@ -110,6 +87,29 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextU
11087
next.syntax().text_range().start() + TextUnit::of_str(next.prefix()),
11188
));
11289
} else {
90+
// Special case that turns something like:
91+
//
92+
// ```
93+
// my_function({<|>
94+
// <some-expr>
95+
// })
96+
// ```
97+
//
98+
// into `my_function(<some-expr>)`
99+
if join_single_expr_block(edit, token).is_some() {
100+
return;
101+
}
102+
// ditto for
103+
//
104+
// ```
105+
// use foo::{<|>
106+
// bar
107+
// };
108+
// ```
109+
if join_single_use_tree(edit, token).is_some() {
110+
return;
111+
}
112+
113113
// Remove newline but add a computed amount of whitespace characters
114114
edit.replace(token.text_range(), compute_ws(prev.kind(), next.kind()).to_string());
115115
}
@@ -608,4 +608,27 @@ pub fn handle_find_matching_brace() {
608608
}",
609609
);
610610
}
611+
612+
#[test]
613+
fn test_join_lines_commented_block() {
614+
check_join_lines(
615+
r"
616+
fn main() {
617+
let _ = {
618+
// <|>foo
619+
// bar
620+
92
621+
};
622+
}
623+
",
624+
r"
625+
fn main() {
626+
let _ = {
627+
// <|>foo bar
628+
92
629+
};
630+
}
631+
",
632+
)
633+
}
611634
}

0 commit comments

Comments
 (0)