mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
fix: join lines doesn't add space before closing quote
This commit is contained in:
parent
b43921cddd
commit
e0da3da0d9
@ -65,11 +65,15 @@ fn remove_newlines(edit: &mut TextEditBuilder, token: &SyntaxToken, range: TextR
|
|||||||
|
|
||||||
fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextSize) {
|
fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextSize) {
|
||||||
if token.kind() != WHITESPACE || token.text().bytes().filter(|&b| b == b'\n').count() != 1 {
|
if token.kind() != WHITESPACE || token.text().bytes().filter(|&b| b == b'\n').count() != 1 {
|
||||||
let mut string_open_quote = false;
|
let mut no_space = false;
|
||||||
if let Some(string) = ast::String::cast(token.clone()) {
|
if let Some(string) = ast::String::cast(token.clone()) {
|
||||||
if let Some(range) = string.open_quote_text_range() {
|
if let Some(range) = string.open_quote_text_range() {
|
||||||
cov_mark::hit!(join_string_literal);
|
cov_mark::hit!(join_string_literal_open_quote);
|
||||||
string_open_quote = range.end() == offset;
|
no_space |= range.end() == offset;
|
||||||
|
}
|
||||||
|
if let Some(range) = string.close_quote_text_range() {
|
||||||
|
cov_mark::hit!(join_string_literal_close_quote);
|
||||||
|
no_space |= range.start() == offset + TextSize::of('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -82,7 +86,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextS
|
|||||||
};
|
};
|
||||||
|
|
||||||
let range = TextRange::at(offset, ((n_spaces_after_line_break + 1) as u32).into());
|
let range = TextRange::at(offset, ((n_spaces_after_line_break + 1) as u32).into());
|
||||||
let replace_with = if string_open_quote { "" } else { " " };
|
let replace_with = if no_space { "" } else { " " };
|
||||||
edit.replace(range, replace_with.to_string());
|
edit.replace(range, replace_with.to_string());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -797,7 +801,8 @@ fn foo() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn join_string_literal() {
|
fn join_string_literal() {
|
||||||
cov_mark::check!(join_string_literal);
|
{
|
||||||
|
cov_mark::check!(join_string_literal_open_quote);
|
||||||
check_join_lines(
|
check_join_lines(
|
||||||
r#"
|
r#"
|
||||||
fn main() {
|
fn main() {
|
||||||
@ -813,6 +818,24 @@ fn main() {
|
|||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
cov_mark::check!(join_string_literal_close_quote);
|
||||||
|
check_join_lines(
|
||||||
|
r#"
|
||||||
|
fn main() {
|
||||||
|
$0"hello
|
||||||
|
";
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
fn main() {
|
||||||
|
$0"hello";
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
check_join_lines(
|
check_join_lines(
|
||||||
r#"
|
r#"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user