diff options
author | Alan Du <[email protected]> | 2019-01-05 03:01:11 +0000 |
---|---|---|
committer | Alan Du <[email protected]> | 2019-01-05 03:01:11 +0000 |
commit | 182ec76f135d0b213d6abea486521e81796bca46 (patch) | |
tree | 8554a5712f0c4f4e99cf998dba6b8d57fb3c2813 /crates | |
parent | fae89605547d684d39e0065fc4286f8608428d5f (diff) |
Address join lines use items right }
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_editor/src/typing.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs index 5876f9e20..2befd5266 100644 --- a/crates/ra_editor/src/typing.rs +++ b/crates/ra_editor/src/typing.rs | |||
@@ -188,10 +188,14 @@ fn remove_newline( | |||
188 | edit.delete(TextRange::from_to(prev.range().start(), node.range().end())); | 188 | edit.delete(TextRange::from_to(prev.range().start(), node.range().end())); |
189 | } else if prev.kind() == COMMA && next.kind() == R_CURLY { | 189 | } else if prev.kind() == COMMA && next.kind() == R_CURLY { |
190 | // Removes: comma, newline (incl. surrounding whitespace) | 190 | // Removes: comma, newline (incl. surrounding whitespace) |
191 | // Adds: a single whitespace | 191 | let space = if let Some(USE_TREE) = prev.prev_sibling().map(|p| p.kind()) { |
192 | "" | ||
193 | } else { | ||
194 | " " | ||
195 | }; | ||
192 | edit.replace( | 196 | edit.replace( |
193 | TextRange::from_to(prev.range().start(), node.range().end()), | 197 | TextRange::from_to(prev.range().start(), node.range().end()), |
194 | " ".to_string(), | 198 | space.to_string(), |
195 | ); | 199 | ); |
196 | } else if let (Some(_), Some(next)) = (ast::Comment::cast(prev), ast::Comment::cast(next)) { | 200 | } else if let (Some(_), Some(next)) = (ast::Comment::cast(prev), ast::Comment::cast(next)) { |
197 | // Removes: newline (incl. surrounding whitespace), start of the next comment | 201 | // Removes: newline (incl. surrounding whitespace), start of the next comment |
@@ -336,7 +340,7 @@ fn foo() { | |||
336 | } | 340 | } |
337 | 341 | ||
338 | #[test] | 342 | #[test] |
339 | fn test_join_lines_use_items() { | 343 | fn test_join_lines_use_items_left() { |
340 | // No space after the '{' | 344 | // No space after the '{' |
341 | check_join_lines( | 345 | check_join_lines( |
342 | r" | 346 | r" |
@@ -350,6 +354,20 @@ fn foo() { | |||
350 | } | 354 | } |
351 | 355 | ||
352 | #[test] | 356 | #[test] |
357 | fn test_join_lines_use_items_right() { | ||
358 | // No space after the '{' | ||
359 | check_join_lines( | ||
360 | r" | ||
361 | use ra_syntax::{ | ||
362 | <|> TextUnit, TextRange, | ||
363 | };", | ||
364 | r" | ||
365 | use ra_syntax::{ | ||
366 | <|> TextUnit, TextRange};", | ||
367 | ); | ||
368 | } | ||
369 | |||
370 | #[test] | ||
353 | fn test_join_lines_use_tree() { | 371 | fn test_join_lines_use_tree() { |
354 | check_join_lines( | 372 | check_join_lines( |
355 | r" | 373 | r" |