diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-03 04:21:45 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-03 04:21:45 +0100 |
commit | b5804296ddceec7694d4787cec8ede726d64b8d2 (patch) | |
tree | d5f7c3ac5b65d58ccaf76e9cd5b3d40be483f8ae /crates/ide/src/join_lines.rs | |
parent | bf695c487a05efecf64475ff4c34a16e90629ff1 (diff) | |
parent | b636080f6738dd390fd8a92df5920f5b0df431d0 (diff) |
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]>
Diffstat (limited to 'crates/ide/src/join_lines.rs')
-rw-r--r-- | crates/ide/src/join_lines.rs | 18 |
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#" | ||
839 | fn main() {$0} | ||
840 | "#, | ||
841 | r#" | ||
842 | fn main() {$0} | ||
843 | "#, | ||
844 | ); | ||
845 | } | ||
832 | } | 846 | } |