diff options
author | Aleksey Kladov <[email protected]> | 2021-05-09 15:17:28 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2021-05-09 15:46:41 +0100 |
commit | 5637ce4250247eef4c2ae1892cead69b6d6a172b (patch) | |
tree | 50ee0b0c50879c9148c374311a5a9e3ea5d7ef87 /crates/ide/src | |
parent | 3f01edebecd5a73fc2abab75a8b29b9d64fd9fa0 (diff) |
fix: join lines doesn't add space before closing quote
Diffstat (limited to 'crates/ide/src')
-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( |