Skip to content

Commit b580429

Browse files
Merge #8305
8305: Fix joinLines panic if run on the empty last line r=edwin0cheng a=edwin0cheng fixes #8299 bors r+ Co-authored-by: Edwin Cheng <[email protected]>
2 parents bf695c4 + b636080 commit b580429

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

crates/ide/src/join_lines.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextS
8888
}
8989

9090
// The node is between two other nodes
91-
let prev = token.prev_sibling_or_token().unwrap();
92-
let next = token.next_sibling_or_token().unwrap();
91+
let (prev, next) = match (token.prev_sibling_or_token(), token.next_sibling_or_token()) {
92+
(Some(prev), Some(next)) => (prev, next),
93+
_ => return,
94+
};
95+
9396
if is_trailing_comma(prev.kind(), next.kind()) {
9497
// Removes: trailing comma, newline (incl. surrounding whitespace)
9598
edit.delete(TextRange::new(prev.text_range().start(), token.text_range().end()));
@@ -826,6 +829,17 @@ fn main() {
826829
$0hello world
827830
";
828831
}
832+
"#,
833+
);
834+
}
835+
#[test]
836+
fn join_last_line_empty() {
837+
check_join_lines(
838+
r#"
839+
fn main() {$0}
840+
"#,
841+
r#"
842+
fn main() {$0}
829843
"#,
830844
);
831845
}

0 commit comments

Comments
 (0)