diff options
Diffstat (limited to 'crates/ide')
-rw-r--r-- | crates/ide/src/join_lines.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/crates/ide/src/join_lines.rs b/crates/ide/src/join_lines.rs index 482b23cf5..3e30e71ce 100644 --- a/crates/ide/src/join_lines.rs +++ b/crates/ide/src/join_lines.rs | |||
@@ -1,3 +1,5 @@ | |||
1 | use std::convert::TryFrom; | ||
2 | |||
1 | use ide_assists::utils::extract_trivial_expression; | 3 | use ide_assists::utils::extract_trivial_expression; |
2 | use itertools::Itertools; | 4 | use itertools::Itertools; |
3 | use syntax::{ | 5 | use syntax::{ |
@@ -85,6 +87,21 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextS | |||
85 | suff.bytes().take_while(|&b| b == b' ').count() | 87 | suff.bytes().take_while(|&b| b == b' ').count() |
86 | }; | 88 | }; |
87 | 89 | ||
90 | let mut no_space = false; | ||
91 | if let Some(string) = ast::String::cast(token.clone()) { | ||
92 | if let Some(range) = string.open_quote_text_range() { | ||
93 | cov_mark::hit!(join_string_literal_open_quote); | ||
94 | no_space |= range.end() == offset; | ||
95 | } | ||
96 | if let Some(range) = string.close_quote_text_range() { | ||
97 | cov_mark::hit!(join_string_literal_close_quote); | ||
98 | no_space |= range.start() | ||
99 | == offset | ||
100 | + TextSize::of('\n') | ||
101 | + TextSize::try_from(n_spaces_after_line_break).unwrap(); | ||
102 | } | ||
103 | } | ||
104 | |||
88 | let range = TextRange::at(offset, ((n_spaces_after_line_break + 1) as u32).into()); | 105 | let range = TextRange::at(offset, ((n_spaces_after_line_break + 1) as u32).into()); |
89 | let replace_with = if no_space { "" } else { " " }; | 106 | let replace_with = if no_space { "" } else { " " }; |
90 | edit.replace(range, replace_with.to_string()); | 107 | edit.replace(range, replace_with.to_string()); |
@@ -835,6 +852,19 @@ fn main() { | |||
835 | } | 852 | } |
836 | "#, | 853 | "#, |
837 | ); | 854 | ); |
855 | check_join_lines( | ||
856 | r#" | ||
857 | fn main() { | ||
858 | $0r"hello | ||
859 | "; | ||
860 | } | ||
861 | "#, | ||
862 | r#" | ||
863 | fn main() { | ||
864 | $0r"hello"; | ||
865 | } | ||
866 | "#, | ||
867 | ); | ||
838 | } | 868 | } |
839 | 869 | ||
840 | check_join_lines( | 870 | check_join_lines( |