aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAlan Du <[email protected]>2019-01-05 03:06:36 +0000
committerAlan Du <[email protected]>2019-01-05 03:06:36 +0000
commit19c641390d2d152cddf9616aef51fa291260d289 (patch)
tree2db0bab5138a94d4c4d798b0a08c0003ad2891a4 /crates
parent182ec76f135d0b213d6abea486521e81796bca46 (diff)
Fix join_lines use_items right w/ and w/o comma
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_editor/src/typing.rs25
1 files changed, 22 insertions, 3 deletions
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(
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 let space = if let Some(USE_TREE) = prev.prev_sibling().map(|p| p.kind()) { 191 let space = if let Some(left) = prev.prev_sibling() {
192 "" 192 compute_ws(left, next)
193 } else { 193 } else {
194 " " 194 " "
195 }; 195 };
@@ -269,6 +269,11 @@ fn compute_ws(left: SyntaxNodeRef, right: SyntaxNodeRef) -> &'static str {
269 } 269 }
270 match right.kind() { 270 match right.kind() {
271 R_PAREN | R_BRACK => return "", 271 R_PAREN | R_BRACK => return "",
272 R_CURLY => {
273 if let USE_TREE = left.kind() {
274 return "";
275 }
276 }
272 DOT => return "", 277 DOT => return "",
273 _ => (), 278 _ => (),
274 } 279 }
@@ -355,7 +360,21 @@ fn foo() {
355 360
356 #[test] 361 #[test]
357 fn test_join_lines_use_items_right() { 362 fn test_join_lines_use_items_right() {
358 // No space after the '{' 363 // No space after the '}'
364 check_join_lines(
365 r"
366use ra_syntax::{
367<|> TextUnit, TextRange
368};",
369 r"
370use ra_syntax::{
371<|> TextUnit, TextRange};",
372 );
373 }
374
375 #[test]
376 fn test_join_lines_use_items_right_comma() {
377 // No space after the '}'
359 check_join_lines( 378 check_join_lines(
360 r" 379 r"
361use ra_syntax::{ 380use ra_syntax::{