aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAdolfo OchagavĂ­a <[email protected]>2018-10-11 16:16:12 +0100
committerAdolfo OchagavĂ­a <[email protected]>2018-10-11 16:16:12 +0100
commit6fe77db41307da8ead8a0b0355488221b61c0349 (patch)
treed57e995a10c8f8faf837e9be327fe5c618148281 /crates
parent92f5ca64ae09ab996e83acb4017e355437eddc86 (diff)
Remove smart multiline comment join
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_editor/src/typing.rs45
1 files changed, 23 insertions, 22 deletions
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs
index 97ff01e40..1dc658f9b 100644
--- a/crates/ra_editor/src/typing.rs
+++ b/crates/ra_editor/src/typing.rs
@@ -174,27 +174,10 @@ fn remove_newline(
174 ); 174 );
175 } else if let (Some(_), Some(next)) = (ast::Comment::cast(prev), ast::Comment::cast(next)) { 175 } else if let (Some(_), Some(next)) = (ast::Comment::cast(prev), ast::Comment::cast(next)) {
176 // Removes: newline (incl. surrounding whitespace), start of the next comment 176 // Removes: newline (incl. surrounding whitespace), start of the next comment
177 let comment_text = next.text(); 177 edit.delete(TextRange::from_to(
178 if let Some(newline_pos) = comment_text.find('\n') { 178 node.range().start(),
179 // Special case for multiline comments: join the comment content but 179 next.syntax().range().start() + TextUnit::of_str(next.prefix())
180 // keep the leading `/*` 180 ));
181
182 let newline_offset = next.syntax().range().start()
183 + TextUnit::from(newline_pos as u32)
184 + TextUnit::of_char('\n');
185
186 edit.insert(newline_offset, "/*".to_string());
187 edit.delete(TextRange::from_to(
188 node.range().start(),
189 next.syntax().range().start() + TextUnit::of_str(next.prefix())
190 ));
191 } else {
192 // Single-line comments
193 edit.delete(TextRange::from_to(
194 node.range().start(),
195 next.syntax().range().start() + TextUnit::of_str(next.prefix())
196 ));
197 }
198 } else { 181 } else {
199 // Remove newline but add a computed amount of whitespace characters 182 // Remove newline but add a computed amount of whitespace characters
200 edit.replace( 183 edit.replace(
@@ -356,7 +339,7 @@ fn foo() {
356 } 339 }
357 340
358 #[test] 341 #[test]
359 fn test_join_lines_multiline_comments() { 342 fn test_join_lines_multiline_comments_1() {
360 check_join_lines(r" 343 check_join_lines(r"
361fn foo() { 344fn foo() {
362 // Hello<|> 345 // Hello<|>
@@ -369,6 +352,24 @@ fn foo() {
369"); 352");
370 } 353 }
371 354
355 #[test]
356 fn test_join_lines_multiline_comments_2() {
357 check_join_lines(r"
358fn foo() {
359 // The<|>
360 /* quick
361 brown
362 fox! */
363}
364", r"
365fn foo() {
366 // The<|> quick
367 brown
368 fox! */
369}
370");
371 }
372
372 fn check_join_lines_sel(before: &str, after: &str) { 373 fn check_join_lines_sel(before: &str, after: &str) {
373 let (sel, before) = extract_range(before); 374 let (sel, before) = extract_range(before);
374 let file = File::parse(&before); 375 let file = File::parse(&before);