From 19c641390d2d152cddf9616aef51fa291260d289 Mon Sep 17 00:00:00 2001 From: Alan Du Date: Fri, 4 Jan 2019 22:06:36 -0500 Subject: Fix join_lines use_items right w/ and w/o comma --- crates/ra_editor/src/typing.rs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'crates/ra_editor/src/typing.rs') diff --git a/crates/ra_editor/src/typing.rs b/crates/ra_editor/src/typing.rs index 2befd5266..1b568e96c 100644 --- a/crates/ra_editor/src/typing.rs +++ b/crates/ra_editor/src/typing.rs @@ -188,8 +188,8 @@ 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) - let space = if let Some(USE_TREE) = prev.prev_sibling().map(|p| p.kind()) { - "" + let space = if let Some(left) = prev.prev_sibling() { + compute_ws(left, next) } else { " " }; @@ -269,6 +269,11 @@ fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str { } match right.kind() { R_PAREN | R_BRACK => return "", + R_CURLY => { + if let USE_TREE = left.kind() { + return ""; + } + } DOT => return "", _ => (), } @@ -355,7 +360,21 @@ fn foo() { #[test] fn test_join_lines_use_items_right() { - // No space after the '{' + // 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_items_right_comma() { + // No space after the '}' check_join_lines( r" use ra_syntax::{ -- cgit v1.2.3