From 5637ce4250247eef4c2ae1892cead69b6d6a172b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 9 May 2021 17:17:28 +0300 Subject: fix: join lines doesn't add space before closing quote --- crates/ide/src/join_lines.rs | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'crates') 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 @@ +use std::convert::TryFrom; + use ide_assists::utils::extract_trivial_expression; use itertools::Itertools; use syntax::{ @@ -85,6 +87,21 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextS suff.bytes().take_while(|&b| b == b' ').count() }; + let mut no_space = false; + if let Some(string) = ast::String::cast(token.clone()) { + if let Some(range) = string.open_quote_text_range() { + cov_mark::hit!(join_string_literal_open_quote); + 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') + + TextSize::try_from(n_spaces_after_line_break).unwrap(); + } + } + let range = TextRange::at(offset, ((n_spaces_after_line_break + 1) as u32).into()); let replace_with = if no_space { "" } else { " " }; edit.replace(range, replace_with.to_string()); @@ -833,6 +850,19 @@ fn main() { fn main() { $0"hello"; } +"#, + ); + check_join_lines( + r#" +fn main() { + $0r"hello + "; +} +"#, + r#" +fn main() { + $0r"hello"; +} "#, ); } -- cgit v1.2.3