aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-05-09 15:17:28 +0100
committerAleksey Kladov <[email protected]>2021-05-09 15:19:18 +0100
commite0da3da0d9a6673bc3b653ce863fec2bdd3f7fab (patch)
tree65ab4a316e07a28f3a16bdcb6f58783b5a07ba01 /crates
parentb43921cdddb4e703787ab87b0ea3f8eaff94f6c9 (diff)
fix: join lines doesn't add space before closing quote
Diffstat (limited to 'crates')
-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 fe2a349e6..482b23cf5 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
65 65
66fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextSize) { 66fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextSize) {
67 if token.kind() != WHITESPACE || token.text().bytes().filter(|&b| b == b'\n').count() != 1 { 67 if token.kind() != WHITESPACE || token.text().bytes().filter(|&b| b == b'\n').count() != 1 {
68 let mut string_open_quote = false; 68 let mut no_space = false;
69 if let Some(string) = ast::String::cast(token.clone()) { 69 if let Some(string) = ast::String::cast(token.clone()) {
70 if let Some(range) = string.open_quote_text_range() { 70 if let Some(range) = string.open_quote_text_range() {
71 cov_mark::hit!(join_string_literal); 71 cov_mark::hit!(join_string_literal_open_quote);
72 string_open_quote = range.end() == offset; 72 no_space |= range.end() == offset;
73 }
74 if let Some(range) = string.close_quote_text_range() {
75 cov_mark::hit!(join_string_literal_close_quote);
76 no_space |= range.start() == offset + TextSize::of('\n');
73 } 77 }
74 } 78 }
75 79
@@ -82,7 +86,7 @@ fn remove_newline(edit: &mut TextEditBuilder, token: &SyntaxToken, offset: TextS
82 }; 86 };
83 87
84 let range = TextRange::at(offset, ((n_spaces_after_line_break + 1) as u32).into()); 88 let range = TextRange::at(offset, ((n_spaces_after_line_break + 1) as u32).into());
85 let replace_with = if string_open_quote { "" } else { " " }; 89 let replace_with = if no_space { "" } else { " " };
86 edit.replace(range, replace_with.to_string()); 90 edit.replace(range, replace_with.to_string());
87 return; 91 return;
88 } 92 }
@@ -797,22 +801,41 @@ fn foo() {
797 801
798 #[test] 802 #[test]
799 fn join_string_literal() { 803 fn join_string_literal() {
800 cov_mark::check!(join_string_literal); 804 {
801 check_join_lines( 805 cov_mark::check!(join_string_literal_open_quote);
802 r#" 806 check_join_lines(
807 r#"
803fn main() { 808fn main() {
804 $0" 809 $0"
805hello 810hello
806"; 811";
807} 812}
808"#, 813"#,
809 r#" 814 r#"
810fn main() { 815fn main() {
811 $0"hello 816 $0"hello
812"; 817";
813} 818}
814"#, 819"#,
815 ); 820 );
821 }
822
823 {
824 cov_mark::check!(join_string_literal_close_quote);
825 check_join_lines(
826 r#"
827fn main() {
828 $0"hello
829";
830}
831"#,
832 r#"
833fn main() {
834 $0"hello";
835}
836"#,
837 );
838 }
816 839
817 check_join_lines( 840 check_join_lines(
818 r#" 841 r#"