aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/handlers/change_visibility.rs9
-rw-r--r--crates/ra_assists/src/handlers/fill_match_arms.rs193
-rw-r--r--crates/ra_assists/src/handlers/fix_visibility.rs64
-rw-r--r--crates/ra_assists/src/handlers/unwrap_block.rs10
-rw-r--r--crates/ra_assists/src/tests/generated.rs4
-rw-r--r--docs/user/assists.md4
6 files changed, 124 insertions, 160 deletions
diff --git a/crates/ra_assists/src/handlers/change_visibility.rs b/crates/ra_assists/src/handlers/change_visibility.rs
index 1d9b8e645..fbe459c9c 100644
--- a/crates/ra_assists/src/handlers/change_visibility.rs
+++ b/crates/ra_assists/src/handlers/change_visibility.rs
@@ -68,7 +68,6 @@ fn add_vis(acc: &mut Assists, ctx: &AssistContext) -> Option<()> {
68 68
69 acc.add(AssistId("change_visibility"), "Change visibility to pub(crate)", target, |edit| { 69 acc.add(AssistId("change_visibility"), "Change visibility to pub(crate)", target, |edit| {
70 edit.insert(offset, "pub(crate) "); 70 edit.insert(offset, "pub(crate) ");
71 edit.set_cursor(offset);
72 }) 71 })
73} 72}
74 73
@@ -92,7 +91,6 @@ fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> {
92 target, 91 target,
93 |edit| { 92 |edit| {
94 edit.replace(vis.syntax().text_range(), "pub(crate)"); 93 edit.replace(vis.syntax().text_range(), "pub(crate)");
95 edit.set_cursor(vis.syntax().text_range().start())
96 }, 94 },
97 ); 95 );
98 } 96 }
@@ -104,7 +102,6 @@ fn change_vis(acc: &mut Assists, vis: ast::Visibility) -> Option<()> {
104 target, 102 target,
105 |edit| { 103 |edit| {
106 edit.replace(vis.syntax().text_range(), "pub"); 104 edit.replace(vis.syntax().text_range(), "pub");
107 edit.set_cursor(vis.syntax().text_range().start());
108 }, 105 },
109 ); 106 );
110 } 107 }
@@ -122,15 +119,15 @@ mod tests {
122 #[test] 119 #[test]
123 fn change_visibility_adds_pub_crate_to_items() { 120 fn change_visibility_adds_pub_crate_to_items() {
124 check_assist(change_visibility, "<|>fn foo() {}", "<|>pub(crate) fn foo() {}"); 121 check_assist(change_visibility, "<|>fn foo() {}", "<|>pub(crate) fn foo() {}");
125 check_assist(change_visibility, "f<|>n foo() {}", "<|>pub(crate) fn foo() {}"); 122 check_assist(change_visibility, "f<|>n foo() {}", "pub(crate) f<|>n foo() {}");
126 check_assist(change_visibility, "<|>struct Foo {}", "<|>pub(crate) struct Foo {}"); 123 check_assist(change_visibility, "<|>struct Foo {}", "<|>pub(crate) struct Foo {}");
127 check_assist(change_visibility, "<|>mod foo {}", "<|>pub(crate) mod foo {}"); 124 check_assist(change_visibility, "<|>mod foo {}", "<|>pub(crate) mod foo {}");
128 check_assist(change_visibility, "<|>trait Foo {}", "<|>pub(crate) trait Foo {}"); 125 check_assist(change_visibility, "<|>trait Foo {}", "<|>pub(crate) trait Foo {}");
129 check_assist(change_visibility, "m<|>od {}", "<|>pub(crate) mod {}"); 126 check_assist(change_visibility, "m<|>od {}", "pub(crate) m<|>od {}");
130 check_assist( 127 check_assist(
131 change_visibility, 128 change_visibility,
132 "unsafe f<|>n foo() {}", 129 "unsafe f<|>n foo() {}",
133 "<|>pub(crate) unsafe fn foo() {}", 130 "pub(crate) unsafe f<|>n foo() {}",
134 ); 131 );
135 } 132 }
136 133
diff --git a/crates/ra_assists/src/handlers/fill_match_arms.rs b/crates/ra_assists/src/handlers/fill_match_arms.rs
index bbdcdc626..cc303285b 100644
--- a/crates/ra_assists/src/handlers/fill_match_arms.rs
+++ b/crates/ra_assists/src/handlers/fill_match_arms.rs
@@ -6,7 +6,10 @@ use ra_ide_db::RootDatabase;
6use ra_syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat}; 6use ra_syntax::ast::{self, make, AstNode, MatchArm, NameOwner, Pat};
7use test_utils::mark; 7use test_utils::mark;
8 8
9use crate::{utils::FamousDefs, AssistContext, AssistId, Assists}; 9use crate::{
10 utils::{render_snippet, Cursor, FamousDefs},
11 AssistContext, AssistId, Assists,
12};
10 13
11// Assist: fill_match_arms 14// Assist: fill_match_arms
12// 15//
@@ -27,7 +30,7 @@ use crate::{utils::FamousDefs, AssistContext, AssistId, Assists};
27// 30//
28// fn handle(action: Action) { 31// fn handle(action: Action) {
29// match action { 32// match action {
30// Action::Move { distance } => {} 33// $0Action::Move { distance } => {}
31// Action::Stop => {} 34// Action::Stop => {}
32// } 35// }
33// } 36// }
@@ -100,10 +103,23 @@ pub(crate) fn fill_match_arms(acc: &mut Assists, ctx: &AssistContext) -> Option<
100 } 103 }
101 104
102 let target = match_expr.syntax().text_range(); 105 let target = match_expr.syntax().text_range();
103 acc.add(AssistId("fill_match_arms"), "Fill match arms", target, |edit| { 106 acc.add(AssistId("fill_match_arms"), "Fill match arms", target, |builder| {
104 let new_arm_list = match_arm_list.remove_placeholder().append_arms(missing_arms); 107 let new_arm_list = match_arm_list.remove_placeholder();
105 edit.set_cursor(expr.syntax().text_range().start()); 108 let n_old_arms = new_arm_list.arms().count();
106 edit.replace_ast(match_arm_list, new_arm_list); 109 let new_arm_list = new_arm_list.append_arms(missing_arms);
110 let first_new_arm = new_arm_list.arms().nth(n_old_arms);
111 let old_range = match_arm_list.syntax().text_range();
112 match (first_new_arm, ctx.config.snippet_cap) {
113 (Some(first_new_arm), Some(cap)) => {
114 let snippet = render_snippet(
115 cap,
116 new_arm_list.syntax(),
117 Cursor::Before(first_new_arm.syntax()),
118 );
119 builder.replace_snippet(cap, old_range, snippet);
120 }
121 _ => builder.replace(old_range, new_arm_list.to_string()),
122 }
107 }) 123 })
108} 124}
109 125
@@ -226,12 +242,12 @@ mod tests {
226 r#" 242 r#"
227 enum A { 243 enum A {
228 As, 244 As,
229 Bs{x:i32, y:Option<i32>}, 245 Bs { x: i32, y: Option<i32> },
230 Cs(i32, Option<i32>), 246 Cs(i32, Option<i32>),
231 } 247 }
232 fn main() { 248 fn main() {
233 match A::As<|> { 249 match A::As<|> {
234 A::Bs{x,y:Some(_)} => {} 250 A::Bs { x, y: Some(_) } => {}
235 A::Cs(_, Some(_)) => {} 251 A::Cs(_, Some(_)) => {}
236 } 252 }
237 } 253 }
@@ -239,14 +255,14 @@ mod tests {
239 r#" 255 r#"
240 enum A { 256 enum A {
241 As, 257 As,
242 Bs{x:i32, y:Option<i32>}, 258 Bs { x: i32, y: Option<i32> },
243 Cs(i32, Option<i32>), 259 Cs(i32, Option<i32>),
244 } 260 }
245 fn main() { 261 fn main() {
246 match <|>A::As { 262 match A::As {
247 A::Bs{x,y:Some(_)} => {} 263 A::Bs { x, y: Some(_) } => {}
248 A::Cs(_, Some(_)) => {} 264 A::Cs(_, Some(_)) => {}
249 A::As => {} 265 $0A::As => {}
250 } 266 }
251 } 267 }
252 "#, 268 "#,
@@ -276,9 +292,9 @@ mod tests {
276 Cs(Option<i32>), 292 Cs(Option<i32>),
277 } 293 }
278 fn main() { 294 fn main() {
279 match <|>A::As { 295 match A::As {
280 A::Cs(_) | A::Bs => {} 296 A::Cs(_) | A::Bs => {}
281 A::As => {} 297 $0A::As => {}
282 } 298 }
283 } 299 }
284 "#, 300 "#,
@@ -322,11 +338,11 @@ mod tests {
322 Ys, 338 Ys,
323 } 339 }
324 fn main() { 340 fn main() {
325 match <|>A::As { 341 match A::As {
326 A::Bs if 0 < 1 => {} 342 A::Bs if 0 < 1 => {}
327 A::Ds(_value) => { let x = 1; } 343 A::Ds(_value) => { let x = 1; }
328 A::Es(B::Xs) => (), 344 A::Es(B::Xs) => (),
329 A::As => {} 345 $0A::As => {}
330 A::Cs => {} 346 A::Cs => {}
331 } 347 }
332 } 348 }
@@ -344,7 +360,7 @@ mod tests {
344 Bs, 360 Bs,
345 Cs(String), 361 Cs(String),
346 Ds(String, String), 362 Ds(String, String),
347 Es{ x: usize, y: usize } 363 Es { x: usize, y: usize }
348 } 364 }
349 365
350 fn main() { 366 fn main() {
@@ -358,13 +374,13 @@ mod tests {
358 Bs, 374 Bs,
359 Cs(String), 375 Cs(String),
360 Ds(String, String), 376 Ds(String, String),
361 Es{ x: usize, y: usize } 377 Es { x: usize, y: usize }
362 } 378 }
363 379
364 fn main() { 380 fn main() {
365 let a = A::As; 381 let a = A::As;
366 match <|>a { 382 match a {
367 A::As => {} 383 $0A::As => {}
368 A::Bs => {} 384 A::Bs => {}
369 A::Cs(_) => {} 385 A::Cs(_) => {}
370 A::Ds(_, _) => {} 386 A::Ds(_, _) => {}
@@ -380,14 +396,8 @@ mod tests {
380 check_assist( 396 check_assist(
381 fill_match_arms, 397 fill_match_arms,
382 r#" 398 r#"
383 enum A { 399 enum A { One, Two }
384 One, 400 enum B { One, Two }
385 Two,
386 }
387 enum B {
388 One,
389 Two,
390 }
391 401
392 fn main() { 402 fn main() {
393 let a = A::One; 403 let a = A::One;
@@ -396,20 +406,14 @@ mod tests {
396 } 406 }
397 "#, 407 "#,
398 r#" 408 r#"
399 enum A { 409 enum A { One, Two }
400 One, 410 enum B { One, Two }
401 Two,
402 }
403 enum B {
404 One,
405 Two,
406 }
407 411
408 fn main() { 412 fn main() {
409 let a = A::One; 413 let a = A::One;
410 let b = B::One; 414 let b = B::One;
411 match <|>(a, b) { 415 match (a, b) {
412 (A::One, B::One) => {} 416 $0(A::One, B::One) => {}
413 (A::One, B::Two) => {} 417 (A::One, B::Two) => {}
414 (A::Two, B::One) => {} 418 (A::Two, B::One) => {}
415 (A::Two, B::Two) => {} 419 (A::Two, B::Two) => {}
@@ -424,14 +428,8 @@ mod tests {
424 check_assist( 428 check_assist(
425 fill_match_arms, 429 fill_match_arms,
426 r#" 430 r#"
427 enum A { 431 enum A { One, Two }
428 One, 432 enum B { One, Two }
429 Two,
430 }
431 enum B {
432 One,
433 Two,
434 }
435 433
436 fn main() { 434 fn main() {
437 let a = A::One; 435 let a = A::One;
@@ -440,20 +438,14 @@ mod tests {
440 } 438 }
441 "#, 439 "#,
442 r#" 440 r#"
443 enum A { 441 enum A { One, Two }
444 One, 442 enum B { One, Two }
445 Two,
446 }
447 enum B {
448 One,
449 Two,
450 }
451 443
452 fn main() { 444 fn main() {
453 let a = A::One; 445 let a = A::One;
454 let b = B::One; 446 let b = B::One;
455 match <|>(&a, &b) { 447 match (&a, &b) {
456 (A::One, B::One) => {} 448 $0(A::One, B::One) => {}
457 (A::One, B::Two) => {} 449 (A::One, B::Two) => {}
458 (A::Two, B::One) => {} 450 (A::Two, B::One) => {}
459 (A::Two, B::Two) => {} 451 (A::Two, B::Two) => {}
@@ -468,14 +460,8 @@ mod tests {
468 check_assist_not_applicable( 460 check_assist_not_applicable(
469 fill_match_arms, 461 fill_match_arms,
470 r#" 462 r#"
471 enum A { 463 enum A { One, Two }
472 One, 464 enum B { One, Two }
473 Two,
474 }
475 enum B {
476 One,
477 Two,
478 }
479 465
480 fn main() { 466 fn main() {
481 let a = A::One; 467 let a = A::One;
@@ -493,14 +479,8 @@ mod tests {
493 check_assist_not_applicable( 479 check_assist_not_applicable(
494 fill_match_arms, 480 fill_match_arms,
495 r#" 481 r#"
496 enum A { 482 enum A { One, Two }
497 One, 483 enum B { One, Two }
498 Two,
499 }
500 enum B {
501 One,
502 Two,
503 }
504 484
505 fn main() { 485 fn main() {
506 let a = A::One; 486 let a = A::One;
@@ -524,10 +504,7 @@ mod tests {
524 check_assist_not_applicable( 504 check_assist_not_applicable(
525 fill_match_arms, 505 fill_match_arms,
526 r#" 506 r#"
527 enum A { 507 enum A { One, Two }
528 One,
529 Two,
530 }
531 508
532 fn main() { 509 fn main() {
533 let a = A::One; 510 let a = A::One;
@@ -543,9 +520,7 @@ mod tests {
543 check_assist( 520 check_assist(
544 fill_match_arms, 521 fill_match_arms,
545 r#" 522 r#"
546 enum A { 523 enum A { As }
547 As,
548 }
549 524
550 fn foo(a: &A) { 525 fn foo(a: &A) {
551 match a<|> { 526 match a<|> {
@@ -553,13 +528,11 @@ mod tests {
553 } 528 }
554 "#, 529 "#,
555 r#" 530 r#"
556 enum A { 531 enum A { As }
557 As,
558 }
559 532
560 fn foo(a: &A) { 533 fn foo(a: &A) {
561 match <|>a { 534 match a {
562 A::As => {} 535 $0A::As => {}
563 } 536 }
564 } 537 }
565 "#, 538 "#,
@@ -569,7 +542,7 @@ mod tests {
569 fill_match_arms, 542 fill_match_arms,
570 r#" 543 r#"
571 enum A { 544 enum A {
572 Es{ x: usize, y: usize } 545 Es { x: usize, y: usize }
573 } 546 }
574 547
575 fn foo(a: &mut A) { 548 fn foo(a: &mut A) {
@@ -579,12 +552,12 @@ mod tests {
579 "#, 552 "#,
580 r#" 553 r#"
581 enum A { 554 enum A {
582 Es{ x: usize, y: usize } 555 Es { x: usize, y: usize }
583 } 556 }
584 557
585 fn foo(a: &mut A) { 558 fn foo(a: &mut A) {
586 match <|>a { 559 match a {
587 A::Es { x, y } => {} 560 $0A::Es { x, y } => {}
588 } 561 }
589 } 562 }
590 "#, 563 "#,
@@ -623,8 +596,8 @@ mod tests {
623 enum E { X, Y } 596 enum E { X, Y }
624 597
625 fn main() { 598 fn main() {
626 match <|>E::X { 599 match E::X {
627 E::X => {} 600 $0E::X => {}
628 E::Y => {} 601 E::Y => {}
629 } 602 }
630 } 603 }
@@ -651,8 +624,8 @@ mod tests {
651 use foo::E::X; 624 use foo::E::X;
652 625
653 fn main() { 626 fn main() {
654 match <|>X { 627 match X {
655 X => {} 628 $0X => {}
656 foo::E::Y => {} 629 foo::E::Y => {}
657 } 630 }
658 } 631 }
@@ -665,10 +638,7 @@ mod tests {
665 check_assist( 638 check_assist(
666 fill_match_arms, 639 fill_match_arms,
667 r#" 640 r#"
668 enum A { 641 enum A { One, Two }
669 One,
670 Two,
671 }
672 fn foo(a: A) { 642 fn foo(a: A) {
673 match a { 643 match a {
674 // foo bar baz<|> 644 // foo bar baz<|>
@@ -678,16 +648,13 @@ mod tests {
678 } 648 }
679 "#, 649 "#,
680 r#" 650 r#"
681 enum A { 651 enum A { One, Two }
682 One,
683 Two,
684 }
685 fn foo(a: A) { 652 fn foo(a: A) {
686 match <|>a { 653 match a {
687 // foo bar baz 654 // foo bar baz
688 A::One => {} 655 A::One => {}
689 // This is where the rest should be 656 // This is where the rest should be
690 A::Two => {} 657 $0A::Two => {}
691 } 658 }
692 } 659 }
693 "#, 660 "#,
@@ -699,10 +666,7 @@ mod tests {
699 check_assist( 666 check_assist(
700 fill_match_arms, 667 fill_match_arms,
701 r#" 668 r#"
702 enum A { 669 enum A { One, Two }
703 One,
704 Two,
705 }
706 fn foo(a: A) { 670 fn foo(a: A) {
707 match a { 671 match a {
708 // foo bar baz<|> 672 // foo bar baz<|>
@@ -710,14 +674,11 @@ mod tests {
710 } 674 }
711 "#, 675 "#,
712 r#" 676 r#"
713 enum A { 677 enum A { One, Two }
714 One,
715 Two,
716 }
717 fn foo(a: A) { 678 fn foo(a: A) {
718 match <|>a { 679 match a {
719 // foo bar baz 680 // foo bar baz
720 A::One => {} 681 $0A::One => {}
721 A::Two => {} 682 A::Two => {}
722 } 683 }
723 } 684 }
@@ -740,8 +701,8 @@ mod tests {
740 r#" 701 r#"
741 enum A { One, Two, } 702 enum A { One, Two, }
742 fn foo(a: A) { 703 fn foo(a: A) {
743 match <|>a { 704 match a {
744 A::One => {} 705 $0A::One => {}
745 A::Two => {} 706 A::Two => {}
746 } 707 }
747 } 708 }
@@ -765,8 +726,8 @@ fn foo(opt: Option<i32>) {
765 before, 726 before,
766 r#" 727 r#"
767fn foo(opt: Option<i32>) { 728fn foo(opt: Option<i32>) {
768 match <|>opt { 729 match opt {
769 Some(_) => {} 730 $0Some(_) => {}
770 None => {} 731 None => {}
771 } 732 }
772} 733}
diff --git a/crates/ra_assists/src/handlers/fix_visibility.rs b/crates/ra_assists/src/handlers/fix_visibility.rs
index 48ce07ca5..9ec42f568 100644
--- a/crates/ra_assists/src/handlers/fix_visibility.rs
+++ b/crates/ra_assists/src/handlers/fix_visibility.rs
@@ -25,7 +25,7 @@ use crate::{AssistContext, AssistId, Assists};
25// -> 25// ->
26// ``` 26// ```
27// mod m { 27// mod m {
28// pub(crate) fn frobnicate() {} 28// $0pub(crate) fn frobnicate() {}
29// } 29// }
30// fn main() { 30// fn main() {
31// m::frobnicate() {} 31// m::frobnicate() {}
@@ -62,10 +62,12 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext) -> O
62 Some(name) => format!("Change visibility of {} to {}", name, missing_visibility), 62 Some(name) => format!("Change visibility of {} to {}", name, missing_visibility),
63 }; 63 };
64 64
65 acc.add(AssistId("fix_visibility"), assist_label, target, |edit| { 65 acc.add(AssistId("fix_visibility"), assist_label, target, |builder| {
66 edit.set_file(target_file); 66 builder.set_file(target_file);
67 edit.insert(offset, format!("{} ", missing_visibility)); 67 match ctx.config.snippet_cap {
68 edit.set_cursor(offset); 68 Some(cap) => builder.insert_snippet(cap, offset, format!("$0{} ", missing_visibility)),
69 None => builder.insert(offset, format!("{} ", missing_visibility)),
70 }
69 }) 71 })
70} 72}
71 73
@@ -103,10 +105,12 @@ fn add_vis_to_referenced_record_field(acc: &mut Assists, ctx: &AssistContext) ->
103 let assist_label = 105 let assist_label =
104 format!("Change visibility of {}.{} to {}", parent_name, target_name, missing_visibility); 106 format!("Change visibility of {}.{} to {}", parent_name, target_name, missing_visibility);
105 107
106 acc.add(AssistId("fix_visibility"), assist_label, target, |edit| { 108 acc.add(AssistId("fix_visibility"), assist_label, target, |builder| {
107 edit.set_file(target_file); 109 builder.set_file(target_file);
108 edit.insert(offset, format!("{} ", missing_visibility)); 110 match ctx.config.snippet_cap {
109 edit.set_cursor(offset) 111 Some(cap) => builder.insert_snippet(cap, offset, format!("$0{} ", missing_visibility)),
112 None => builder.insert(offset, format!("{} ", missing_visibility)),
113 }
110 }) 114 })
111} 115}
112 116
@@ -196,7 +200,7 @@ mod tests {
196 fix_visibility, 200 fix_visibility,
197 r"mod foo { fn foo() {} } 201 r"mod foo { fn foo() {} }
198 fn main() { foo::foo<|>() } ", 202 fn main() { foo::foo<|>() } ",
199 r"mod foo { <|>pub(crate) fn foo() {} } 203 r"mod foo { $0pub(crate) fn foo() {} }
200 fn main() { foo::foo() } ", 204 fn main() { foo::foo() } ",
201 ); 205 );
202 check_assist_not_applicable( 206 check_assist_not_applicable(
@@ -212,7 +216,7 @@ mod tests {
212 fix_visibility, 216 fix_visibility,
213 r"mod foo { struct Foo; } 217 r"mod foo { struct Foo; }
214 fn main() { foo::Foo<|> } ", 218 fn main() { foo::Foo<|> } ",
215 r"mod foo { <|>pub(crate) struct Foo; } 219 r"mod foo { $0pub(crate) struct Foo; }
216 fn main() { foo::Foo } ", 220 fn main() { foo::Foo } ",
217 ); 221 );
218 check_assist_not_applicable( 222 check_assist_not_applicable(
@@ -224,7 +228,7 @@ mod tests {
224 fix_visibility, 228 fix_visibility,
225 r"mod foo { enum Foo; } 229 r"mod foo { enum Foo; }
226 fn main() { foo::Foo<|> } ", 230 fn main() { foo::Foo<|> } ",
227 r"mod foo { <|>pub(crate) enum Foo; } 231 r"mod foo { $0pub(crate) enum Foo; }
228 fn main() { foo::Foo } ", 232 fn main() { foo::Foo } ",
229 ); 233 );
230 check_assist_not_applicable( 234 check_assist_not_applicable(
@@ -236,7 +240,7 @@ mod tests {
236 fix_visibility, 240 fix_visibility,
237 r"mod foo { union Foo; } 241 r"mod foo { union Foo; }
238 fn main() { foo::Foo<|> } ", 242 fn main() { foo::Foo<|> } ",
239 r"mod foo { <|>pub(crate) union Foo; } 243 r"mod foo { $0pub(crate) union Foo; }
240 fn main() { foo::Foo } ", 244 fn main() { foo::Foo } ",
241 ); 245 );
242 check_assist_not_applicable( 246 check_assist_not_applicable(
@@ -258,7 +262,7 @@ mod tests {
258 //- /foo.rs 262 //- /foo.rs
259 struct Foo; 263 struct Foo;
260 ", 264 ",
261 r"<|>pub(crate) struct Foo; 265 r"$0pub(crate) struct Foo;
262 266
263", 267",
264 ); 268 );
@@ -270,7 +274,7 @@ mod tests {
270 fix_visibility, 274 fix_visibility,
271 r"mod foo { pub struct Foo { bar: (), } } 275 r"mod foo { pub struct Foo { bar: (), } }
272 fn main() { foo::Foo { <|>bar: () }; } ", 276 fn main() { foo::Foo { <|>bar: () }; } ",
273 r"mod foo { pub struct Foo { <|>pub(crate) bar: (), } } 277 r"mod foo { pub struct Foo { $0pub(crate) bar: (), } }
274 fn main() { foo::Foo { bar: () }; } ", 278 fn main() { foo::Foo { bar: () }; } ",
275 ); 279 );
276 check_assist( 280 check_assist(
@@ -281,7 +285,7 @@ mod tests {
281 //- /foo.rs 285 //- /foo.rs
282 pub struct Foo { bar: () } 286 pub struct Foo { bar: () }
283 ", 287 ",
284 r"pub struct Foo { <|>pub(crate) bar: () } 288 r"pub struct Foo { $0pub(crate) bar: () }
285 289
286", 290",
287 ); 291 );
@@ -307,7 +311,7 @@ mod tests {
307 fix_visibility, 311 fix_visibility,
308 r"mod foo { pub enum Foo { Bar { bar: () } } } 312 r"mod foo { pub enum Foo { Bar { bar: () } } }
309 fn main() { foo::Foo::Bar { <|>bar: () }; } ", 313 fn main() { foo::Foo::Bar { <|>bar: () }; } ",
310 r"mod foo { pub enum Foo { Bar { <|>pub(crate) bar: () } } } 314 r"mod foo { pub enum Foo { Bar { $0pub(crate) bar: () } } }
311 fn main() { foo::Foo::Bar { bar: () }; } ", 315 fn main() { foo::Foo::Bar { bar: () }; } ",
312 ); 316 );
313 check_assist( 317 check_assist(
@@ -318,7 +322,7 @@ mod tests {
318 //- /foo.rs 322 //- /foo.rs
319 pub enum Foo { Bar { bar: () } } 323 pub enum Foo { Bar { bar: () } }
320 ", 324 ",
321 r"pub enum Foo { Bar { <|>pub(crate) bar: () } } 325 r"pub enum Foo { Bar { $0pub(crate) bar: () } }
322 326
323", 327",
324 ); 328 );
@@ -346,7 +350,7 @@ mod tests {
346 fix_visibility, 350 fix_visibility,
347 r"mod foo { pub union Foo { bar: (), } } 351 r"mod foo { pub union Foo { bar: (), } }
348 fn main() { foo::Foo { <|>bar: () }; } ", 352 fn main() { foo::Foo { <|>bar: () }; } ",
349 r"mod foo { pub union Foo { <|>pub(crate) bar: (), } } 353 r"mod foo { pub union Foo { $0pub(crate) bar: (), } }
350 fn main() { foo::Foo { bar: () }; } ", 354 fn main() { foo::Foo { bar: () }; } ",
351 ); 355 );
352 check_assist( 356 check_assist(
@@ -357,7 +361,7 @@ mod tests {
357 //- /foo.rs 361 //- /foo.rs
358 pub union Foo { bar: () } 362 pub union Foo { bar: () }
359 ", 363 ",
360 r"pub union Foo { <|>pub(crate) bar: () } 364 r"pub union Foo { $0pub(crate) bar: () }
361 365
362", 366",
363 ); 367 );
@@ -383,7 +387,7 @@ mod tests {
383 fix_visibility, 387 fix_visibility,
384 r"mod foo { const FOO: () = (); } 388 r"mod foo { const FOO: () = (); }
385 fn main() { foo::FOO<|> } ", 389 fn main() { foo::FOO<|> } ",
386 r"mod foo { <|>pub(crate) const FOO: () = (); } 390 r"mod foo { $0pub(crate) const FOO: () = (); }
387 fn main() { foo::FOO } ", 391 fn main() { foo::FOO } ",
388 ); 392 );
389 check_assist_not_applicable( 393 check_assist_not_applicable(
@@ -399,7 +403,7 @@ mod tests {
399 fix_visibility, 403 fix_visibility,
400 r"mod foo { static FOO: () = (); } 404 r"mod foo { static FOO: () = (); }
401 fn main() { foo::FOO<|> } ", 405 fn main() { foo::FOO<|> } ",
402 r"mod foo { <|>pub(crate) static FOO: () = (); } 406 r"mod foo { $0pub(crate) static FOO: () = (); }
403 fn main() { foo::FOO } ", 407 fn main() { foo::FOO } ",
404 ); 408 );
405 check_assist_not_applicable( 409 check_assist_not_applicable(
@@ -415,7 +419,7 @@ mod tests {
415 fix_visibility, 419 fix_visibility,
416 r"mod foo { trait Foo { fn foo(&self) {} } } 420 r"mod foo { trait Foo { fn foo(&self) {} } }
417 fn main() { let x: &dyn foo::<|>Foo; } ", 421 fn main() { let x: &dyn foo::<|>Foo; } ",
418 r"mod foo { <|>pub(crate) trait Foo { fn foo(&self) {} } } 422 r"mod foo { $0pub(crate) trait Foo { fn foo(&self) {} } }
419 fn main() { let x: &dyn foo::Foo; } ", 423 fn main() { let x: &dyn foo::Foo; } ",
420 ); 424 );
421 check_assist_not_applicable( 425 check_assist_not_applicable(
@@ -431,7 +435,7 @@ mod tests {
431 fix_visibility, 435 fix_visibility,
432 r"mod foo { type Foo = (); } 436 r"mod foo { type Foo = (); }
433 fn main() { let x: foo::Foo<|>; } ", 437 fn main() { let x: foo::Foo<|>; } ",
434 r"mod foo { <|>pub(crate) type Foo = (); } 438 r"mod foo { $0pub(crate) type Foo = (); }
435 fn main() { let x: foo::Foo; } ", 439 fn main() { let x: foo::Foo; } ",
436 ); 440 );
437 check_assist_not_applicable( 441 check_assist_not_applicable(
@@ -447,7 +451,7 @@ mod tests {
447 fix_visibility, 451 fix_visibility,
448 r"mod foo { mod bar { fn bar() {} } } 452 r"mod foo { mod bar { fn bar() {} } }
449 fn main() { foo::bar<|>::bar(); } ", 453 fn main() { foo::bar<|>::bar(); } ",
450 r"mod foo { <|>pub(crate) mod bar { fn bar() {} } } 454 r"mod foo { $0pub(crate) mod bar { fn bar() {} } }
451 fn main() { foo::bar::bar(); } ", 455 fn main() { foo::bar::bar(); } ",
452 ); 456 );
453 457
@@ -463,7 +467,7 @@ mod tests {
463 pub fn baz() {} 467 pub fn baz() {}
464 } 468 }
465 ", 469 ",
466 r"<|>pub(crate) mod bar { 470 r"$0pub(crate) mod bar {
467 pub fn baz() {} 471 pub fn baz() {}
468} 472}
469 473
@@ -493,7 +497,7 @@ mod tests {
493 pub fn baz() {} 497 pub fn baz() {}
494 } 498 }
495 ", 499 ",
496 r"<|>pub(crate) mod bar; 500 r"$0pub(crate) mod bar;
497", 501",
498 ); 502 );
499 } 503 }
@@ -510,7 +514,7 @@ mod tests {
510 mod bar { 514 mod bar {
511 pub fn baz() {} 515 pub fn baz() {}
512 }", 516 }",
513 r"<|>pub(crate) mod bar { 517 r"$0pub(crate) mod bar {
514 pub fn baz() {} 518 pub fn baz() {}
515} 519}
516", 520",
@@ -525,7 +529,7 @@ mod tests {
525 foo::Bar<|> 529 foo::Bar<|>
526 //- /lib.rs crate:foo 530 //- /lib.rs crate:foo
527 struct Bar;", 531 struct Bar;",
528 r"<|>pub struct Bar; 532 r"$0pub struct Bar;
529", 533",
530 ) 534 )
531 } 535 }
@@ -545,7 +549,7 @@ mod tests {
545 ", 549 ",
546 r" 550 r"
547 mod foo { 551 mod foo {
548 <|>pub(crate) use bar::Baz; 552 $0pub(crate) use bar::Baz;
549 mod bar { pub(super) struct Baz; } 553 mod bar { pub(super) struct Baz; }
550 } 554 }
551 foo::Baz 555 foo::Baz
diff --git a/crates/ra_assists/src/handlers/unwrap_block.rs b/crates/ra_assists/src/handlers/unwrap_block.rs
index e52ec557e..b76182d79 100644
--- a/crates/ra_assists/src/handlers/unwrap_block.rs
+++ b/crates/ra_assists/src/handlers/unwrap_block.rs
@@ -1,8 +1,10 @@
1use crate::{AssistContext, AssistId, Assists};
2
3use ast::{ElseBranch, Expr, LoopBodyOwner};
4use ra_fmt::unwrap_trivial_block; 1use ra_fmt::unwrap_trivial_block;
5use ra_syntax::{ast, match_ast, AstNode, TextRange, T}; 2use ra_syntax::{
3 ast::{self, ElseBranch, Expr, LoopBodyOwner},
4 match_ast, AstNode, TextRange, T,
5};
6
7use crate::{AssistContext, AssistId, Assists};
6 8
7// Assist: unwrap_block 9// Assist: unwrap_block
8// 10//
diff --git a/crates/ra_assists/src/tests/generated.rs b/crates/ra_assists/src/tests/generated.rs
index 417ee89a8..3e6654c17 100644
--- a/crates/ra_assists/src/tests/generated.rs
+++ b/crates/ra_assists/src/tests/generated.rs
@@ -336,7 +336,7 @@ enum Action { Move { distance: u32 }, Stop }
336 336
337fn handle(action: Action) { 337fn handle(action: Action) {
338 match action { 338 match action {
339 Action::Move { distance } => {} 339 $0Action::Move { distance } => {}
340 Action::Stop => {} 340 Action::Stop => {}
341 } 341 }
342} 342}
@@ -358,7 +358,7 @@ fn main() {
358"#####, 358"#####,
359 r#####" 359 r#####"
360mod m { 360mod m {
361 pub(crate) fn frobnicate() {} 361 $0pub(crate) fn frobnicate() {}
362} 362}
363fn main() { 363fn main() {
364 m::frobnicate() {} 364 m::frobnicate() {}
diff --git a/docs/user/assists.md b/docs/user/assists.md
index 0ae242389..51807ffda 100644
--- a/docs/user/assists.md
+++ b/docs/user/assists.md
@@ -325,7 +325,7 @@ enum Action { Move { distance: u32 }, Stop }
325 325
326fn handle(action: Action) { 326fn handle(action: Action) {
327 match action { 327 match action {
328 Action::Move { distance } => {} 328 $0Action::Move { distance } => {}
329 Action::Stop => {} 329 Action::Stop => {}
330 } 330 }
331} 331}
@@ -346,7 +346,7 @@ fn main() {
346 346
347// AFTER 347// AFTER
348mod m { 348mod m {
349 pub(crate) fn frobnicate() {} 349 $0pub(crate) fn frobnicate() {}
350} 350}
351fn main() { 351fn main() {
352 m::frobnicate() {} 352 m::frobnicate() {}