about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-05-09 14:19:39 +0000
committerGitHub <noreply@github.com>2021-05-09 14:19:39 +0000
commit3f01edebecd5a73fc2abab75a8b29b9d64fd9fa0 (patch)
tree65ab4a316e07a28f3a16bdcb6f58783b5a07ba01
parentb43921cdddb4e703787ab87b0ea3f8eaff94f6c9 (diff)
parente0da3da0d9a6673bc3b653ce863fec2bdd3f7fab (diff)
downloadrust-3f01edebecd5a73fc2abab75a8b29b9d64fd9fa0.tar.gz
rust-3f01edebecd5a73fc2abab75a8b29b9d64fd9fa0.zip
Merge #8779
8779: fix: join lines doesn't add space before closing quote r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
-rw-r--r--crates/ide/src/join_lines.rs41
1 files changed, 32 insertions, 9 deletions
diff --git a/crates/ide/src/join_lines.rs b/crates/ide/src/join_lines.rs
index fe2a349e63f..482b23cf5ea 100644
--- a/crates/ide/src/join_lines.rs
+++ b/crates/ide/src/join_lines.rs
@@ -65,11 +65,15 @@ fn remove_newlines(edit: &mut TextEditBuilder, token: &SyntaxToken, range: TextR
 
 fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextSize) {
     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(range) = string.open_quote_text_range() {
-                cov_mark::hit!(join_string_literal);
-                string_open_quote = range.end() == offset;
+                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');
             }
         }
 
@@ -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 replace_with = if string_open_quote { "" } else { " " };
+        let replace_with = if no_space { "" } else { " " };
         edit.replace(range, replace_with.to_string());
         return;
     }
@@ -797,22 +801,41 @@ fn foo() {
 
     #[test]
     fn join_string_literal() {
-        cov_mark::check!(join_string_literal);
-        check_join_lines(
-            r#"
+        {
+            cov_mark::check!(join_string_literal_open_quote);
+            check_join_lines(
+                r#"
 fn main() {
     $0"
 hello
 ";
 }
 "#,
-            r#"
+                r#"
 fn main() {
     $0"hello
 ";
 }
 "#,
-        );
+            );
+        }
+
+        {
+            cov_mark::check!(join_string_literal_close_quote);
+            check_join_lines(
+                r#"
+fn main() {
+    $0"hello
+";
+}
+"#,
+                r#"
+fn main() {
+    $0"hello";
+}
+"#,
+            );
+        }
 
         check_join_lines(
             r#"