From 182ec76f135d0b213d6abea486521e81796bca46 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Fri, 4 Jan 2019 22:01:11 -0500 Subject: Address join lines use items right } --- crates/ra_editor/src/typing.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'crates') 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( edit.delete(TextRange::from_to(prev.range().start(), node.range().end())); } else if prev.kind() == COMMA && next.kind() == R_CURLY { // Removes: comma, newline (incl. surrounding whitespace) - // Adds: a single whitespace + let space = if let Some(USE_TREE) = prev.prev_sibling().map(|p| p.kind()) { + "" + } else { + " " + }; edit.replace( TextRange::from_to(prev.range().start(), node.range().end()), - " ".to_string(), + space.to_string(), ); } else if let (Some(_), Some(next)) = (ast::Comment::cast(prev), ast::Comment::cast(next)) { // Removes: newline (incl. surrounding whitespace), start of the next comment @@ -336,7 +340,7 @@ fn foo() { } #[test] - fn test_join_lines_use_items() { + fn test_join_lines_use_items_left() { // No space after the '{' check_join_lines( r" @@ -349,6 +353,20 @@ fn foo() { ); } + #[test] + fn test_join_lines_use_items_right() { + // No space after the '{' + check_join_lines( + r" +use ra_syntax::{ +<|> TextUnit, TextRange, +};", + r" +use ra_syntax::{ +<|> TextUnit, TextRange};", + ); + } + #[test] fn test_join_lines_use_tree() { check_join_lines( -- cgit v1.2.3