Skip to content

Commit 5637ce4

Browse files
committed
fix: join lines doesn't add space before closing quote
1 parent 3f01ede commit 5637ce4

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

crates/ide/src/join_lines.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
use std::convert::TryFrom;
2+
13
use ide_assists::utils::extract_trivial_expression;
24
use itertools::Itertools;
35
use syntax::{
@@ -85,6 +87,21 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextS
8587
suff.bytes().take_while(|&b| b == b' ').count()
8688
};
8789

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+
88105
let range = TextRange::at(offset, ((n_spaces_after_line_break + 1) as u32).into());
89106
let replace_with = if no_space { "" } else { " " };
90107
edit.replace(range, replace_with.to_string());
@@ -833,6 +850,19 @@ fn main() {
833850
fn main() {
834851
$0"hello";
835852
}
853+
"#,
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+
}
836866
"#,
837867
);
838868
}

0 commit comments

Comments
 (0)