aboutsummaryrefslogtreecommitdiff
path: root/crates/ide/src/join_lines.rs
diff options
context:
space:
mode:
authorEdwin Cheng <[email protected]>2021-04-03 04:20:16 +0100
committerEdwin Cheng <[email protected]>2021-04-03 04:20:16 +0100
commitb636080f6738dd390fd8a92df5920f5b0df431d0 (patch)
treed5f7c3ac5b65d58ccaf76e9cd5b3d40be483f8ae /crates/ide/src/join_lines.rs
parentbf695c487a05efecf64475ff4c34a16e90629ff1 (diff)
Fix joinLines panic if run on the empty last line
Diffstat (limited to 'crates/ide/src/join_lines.rs')
-rw-r--r--crates/ide/src/join_lines.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/crates/ide/src/join_lines.rs b/crates/ide/src/join_lines.rs
index d584190f7..fe2a349e6 100644
--- a/crates/ide/src/join_lines.rs
+++ b/crates/ide/src/join_lines.rs
@@ -88,8 +88,11 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextS
88 } 88 }
89 89
90 // The node is between two other nodes 90 // The node is between two other nodes
91 let prev = token.prev_sibling_or_token().unwrap(); 91 let (prev, next) = match (token.prev_sibling_or_token(), token.next_sibling_or_token()) {
92 let next = token.next_sibling_or_token().unwrap(); 92 (Some(prev), Some(next)) => (prev, next),
93 _ => return,
94 };
95
93 if is_trailing_comma(prev.kind(), next.kind()) { 96 if is_trailing_comma(prev.kind(), next.kind()) {
94 // Removes: trailing comma, newline (incl. surrounding whitespace) 97 // Removes: trailing comma, newline (incl. surrounding whitespace)
95 edit.delete(TextRange::new(prev.text_range().start(), token.text_range().end())); 98 edit.delete(TextRange::new(prev.text_range().start(), token.text_range().end()));
@@ -829,4 +832,15 @@ $0hello world
829"#, 832"#,
830 ); 833 );
831 } 834 }
835 #[test]
836 fn join_last_line_empty() {
837 check_join_lines(
838 r#"
839fn main() {$0}
840"#,
841 r#"
842fn main() {$0}
843"#,
844 );
845 }
832} 846}