diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_ide/src/references/rename.rs | 243 |
1 files changed, 142 insertions, 101 deletions
diff --git a/crates/ra_ide/src/references/rename.rs b/crates/ra_ide/src/references/rename.rs index fbc10d3bb..bbf475f66 100644 --- a/crates/ra_ide/src/references/rename.rs +++ b/crates/ra_ide/src/references/rename.rs | |||
@@ -305,47 +305,17 @@ mod tests { | |||
305 | 305 | ||
306 | #[test] | 306 | #[test] |
307 | fn test_rename_to_underscore() { | 307 | fn test_rename_to_underscore() { |
308 | check( | 308 | check("_", r#"fn main() { let i<|> = 1; }"#, r#"fn main() { let _ = 1; }"#); |
309 | "_", | ||
310 | r#" | ||
311 | fn main() { | ||
312 | let i<|> = 1; | ||
313 | } | ||
314 | "#, | ||
315 | r#" | ||
316 | fn main() { | ||
317 | let _ = 1; | ||
318 | } | ||
319 | "#, | ||
320 | ); | ||
321 | } | 309 | } |
322 | 310 | ||
323 | #[test] | 311 | #[test] |
324 | fn test_rename_to_raw_identifier() { | 312 | fn test_rename_to_raw_identifier() { |
325 | check( | 313 | check("r#fn", r#"fn main() { let i<|> = 1; }"#, r#"fn main() { let r#fn = 1; }"#); |
326 | "r#fn", | ||
327 | r#" | ||
328 | fn main() { | ||
329 | let i<|> = 1; | ||
330 | } | ||
331 | "#, | ||
332 | r#" | ||
333 | fn main() { | ||
334 | let r#fn = 1; | ||
335 | } | ||
336 | "#, | ||
337 | ); | ||
338 | } | 314 | } |
339 | 315 | ||
340 | #[test] | 316 | #[test] |
341 | fn test_rename_to_invalid_identifier() { | 317 | fn test_rename_to_invalid_identifier() { |
342 | let (analysis, position) = analysis_and_position( | 318 | let (analysis, position) = analysis_and_position(r#"fn main() { let i<|> = 1; }"#); |
343 | r#" | ||
344 | fn main() { | ||
345 | let i<|> = 1; | ||
346 | } | ||
347 | "#, | ||
348 | ); | ||
349 | let new_name = "invalid!"; | 319 | let new_name = "invalid!"; |
350 | let source_change = analysis.rename(position, new_name).unwrap(); | 320 | let source_change = analysis.rename(position, new_name).unwrap(); |
351 | assert!(source_change.is_none()); | 321 | assert!(source_change.is_none()); |
@@ -361,9 +331,7 @@ fn main() { | |||
361 | let j = 1; | 331 | let j = 1; |
362 | i = i<|> + j; | 332 | i = i<|> + j; |
363 | 333 | ||
364 | { | 334 | { i = 0; } |
365 | i = 0; | ||
366 | } | ||
367 | 335 | ||
368 | i = 5; | 336 | i = 5; |
369 | } | 337 | } |
@@ -374,9 +342,7 @@ fn main() { | |||
374 | let j = 1; | 342 | let j = 1; |
375 | k = k + j; | 343 | k = k + j; |
376 | 344 | ||
377 | { | 345 | { k = 0; } |
378 | k = 0; | ||
379 | } | ||
380 | 346 | ||
381 | k = 5; | 347 | k = 5; |
382 | } | 348 | } |
@@ -470,53 +436,17 @@ fn main() { | |||
470 | 436 | ||
471 | #[test] | 437 | #[test] |
472 | fn test_rename_for_param_inside() { | 438 | fn test_rename_for_param_inside() { |
473 | check( | 439 | check("j", r#"fn foo(i : u32) -> u32 { i<|> }"#, r#"fn foo(j : u32) -> u32 { j }"#); |
474 | "j", | ||
475 | r#" | ||
476 | fn foo(i : u32) -> u32 { | ||
477 | i<|> | ||
478 | } | ||
479 | "#, | ||
480 | r#" | ||
481 | fn foo(j : u32) -> u32 { | ||
482 | j | ||
483 | } | ||
484 | "#, | ||
485 | ); | ||
486 | } | 440 | } |
487 | 441 | ||
488 | #[test] | 442 | #[test] |
489 | fn test_rename_refs_for_fn_param() { | 443 | fn test_rename_refs_for_fn_param() { |
490 | check( | 444 | check("j", r#"fn foo(i<|> : u32) -> u32 { i }"#, r#"fn foo(j : u32) -> u32 { j }"#); |
491 | "new_name", | ||
492 | r#" | ||
493 | fn foo(i<|> : u32) -> u32 { | ||
494 | i | ||
495 | } | ||
496 | "#, | ||
497 | r#" | ||
498 | fn foo(new_name : u32) -> u32 { | ||
499 | new_name | ||
500 | } | ||
501 | "#, | ||
502 | ); | ||
503 | } | 445 | } |
504 | 446 | ||
505 | #[test] | 447 | #[test] |
506 | fn test_rename_for_mut_param() { | 448 | fn test_rename_for_mut_param() { |
507 | check( | 449 | check("j", r#"fn foo(mut i<|> : u32) -> u32 { i }"#, r#"fn foo(mut j : u32) -> u32 { j }"#); |
508 | "new_name", | ||
509 | r#" | ||
510 | fn foo(mut i<|> : u32) -> u32 { | ||
511 | i | ||
512 | } | ||
513 | "#, | ||
514 | r#" | ||
515 | fn foo(mut new_name : u32) -> u32 { | ||
516 | new_name | ||
517 | } | ||
518 | "#, | ||
519 | ); | ||
520 | } | 450 | } |
521 | 451 | ||
522 | #[test] | 452 | #[test] |
@@ -602,7 +532,6 @@ impl Foo { | |||
602 | "j", | 532 | "j", |
603 | r#" | 533 | r#" |
604 | struct Foo { i<|>: i32 } | 534 | struct Foo { i<|>: i32 } |
605 | |||
606 | struct Bar { i: i32 } | 535 | struct Bar { i: i32 } |
607 | 536 | ||
608 | impl Bar { | 537 | impl Bar { |
@@ -613,7 +542,6 @@ impl Bar { | |||
613 | "#, | 542 | "#, |
614 | r#" | 543 | r#" |
615 | struct Foo { j: i32 } | 544 | struct Foo { j: i32 } |
616 | |||
617 | struct Bar { i: i32 } | 545 | struct Bar { i: i32 } |
618 | 546 | ||
619 | impl Bar { | 547 | impl Bar { |
@@ -721,7 +649,53 @@ pub struct FooContent; | |||
721 | //- /bar.rs | 649 | //- /bar.rs |
722 | use crate::foo<|>::FooContent; | 650 | use crate::foo<|>::FooContent; |
723 | "#, | 651 | "#, |
724 | expect![[]], | 652 | expect![[r#" |
653 | RangeInfo { | ||
654 | range: 11..14, | ||
655 | info: SourceChange { | ||
656 | source_file_edits: [ | ||
657 | SourceFileEdit { | ||
658 | file_id: FileId( | ||
659 | 1, | ||
660 | ), | ||
661 | edit: TextEdit { | ||
662 | indels: [ | ||
663 | Indel { | ||
664 | insert: "quux", | ||
665 | delete: 8..11, | ||
666 | }, | ||
667 | ], | ||
668 | }, | ||
669 | }, | ||
670 | SourceFileEdit { | ||
671 | file_id: FileId( | ||
672 | 3, | ||
673 | ), | ||
674 | edit: TextEdit { | ||
675 | indels: [ | ||
676 | Indel { | ||
677 | insert: "quux", | ||
678 | delete: 11..14, | ||
679 | }, | ||
680 | ], | ||
681 | }, | ||
682 | }, | ||
683 | ], | ||
684 | file_system_edits: [ | ||
685 | MoveFile { | ||
686 | src: FileId( | ||
687 | 2, | ||
688 | ), | ||
689 | anchor: FileId( | ||
690 | 3, | ||
691 | ), | ||
692 | dst: "quux.rs", | ||
693 | }, | ||
694 | ], | ||
695 | is_snippet: false, | ||
696 | }, | ||
697 | } | ||
698 | "#]], | ||
725 | ); | 699 | ); |
726 | } | 700 | } |
727 | 701 | ||
@@ -735,7 +709,40 @@ mod fo<|>o; | |||
735 | //- /foo/mod.rs | 709 | //- /foo/mod.rs |
736 | // emtpy | 710 | // emtpy |
737 | "#, | 711 | "#, |
738 | expect![[]], | 712 | expect![[r#" |
713 | RangeInfo { | ||
714 | range: 4..7, | ||
715 | info: SourceChange { | ||
716 | source_file_edits: [ | ||
717 | SourceFileEdit { | ||
718 | file_id: FileId( | ||
719 | 1, | ||
720 | ), | ||
721 | edit: TextEdit { | ||
722 | indels: [ | ||
723 | Indel { | ||
724 | insert: "foo2", | ||
725 | delete: 4..7, | ||
726 | }, | ||
727 | ], | ||
728 | }, | ||
729 | }, | ||
730 | ], | ||
731 | file_system_edits: [ | ||
732 | MoveFile { | ||
733 | src: FileId( | ||
734 | 2, | ||
735 | ), | ||
736 | anchor: FileId( | ||
737 | 1, | ||
738 | ), | ||
739 | dst: "../foo2/mod.rs", | ||
740 | }, | ||
741 | ], | ||
742 | is_snippet: false, | ||
743 | }, | ||
744 | } | ||
745 | "#]], | ||
739 | ); | 746 | ); |
740 | } | 747 | } |
741 | 748 | ||
@@ -744,22 +751,14 @@ mod fo<|>o; | |||
744 | check( | 751 | check( |
745 | "baz", | 752 | "baz", |
746 | r#" | 753 | r#" |
747 | mod <|>foo { | 754 | mod <|>foo { pub fn bar() {} } |
748 | pub fn bar() {} | ||
749 | } | ||
750 | 755 | ||
751 | fn main() { | 756 | fn main() { foo::bar(); } |
752 | foo::bar(); | ||
753 | } | ||
754 | "#, | 757 | "#, |
755 | r#" | 758 | r#" |
756 | mod baz { | 759 | mod baz { pub fn bar() {} } |
757 | pub fn bar() {} | ||
758 | } | ||
759 | 760 | ||
760 | fn main() { | 761 | fn main() { baz::bar(); } |
761 | baz::bar(); | ||
762 | } | ||
763 | "#, | 762 | "#, |
764 | ); | 763 | ); |
765 | } | 764 | } |
@@ -781,7 +780,53 @@ pub mod foo<|>; | |||
781 | //- /bar/foo.rs | 780 | //- /bar/foo.rs |
782 | // pub fn fun() {} | 781 | // pub fn fun() {} |
783 | "#, | 782 | "#, |
784 | expect![[]], | 783 | expect![[r#" |
784 | RangeInfo { | ||
785 | range: 8..11, | ||
786 | info: SourceChange { | ||
787 | source_file_edits: [ | ||
788 | SourceFileEdit { | ||
789 | file_id: FileId( | ||
790 | 2, | ||
791 | ), | ||
792 | edit: TextEdit { | ||
793 | indels: [ | ||
794 | Indel { | ||
795 | insert: "foo2", | ||
796 | delete: 8..11, | ||
797 | }, | ||
798 | ], | ||
799 | }, | ||
800 | }, | ||
801 | SourceFileEdit { | ||
802 | file_id: FileId( | ||
803 | 1, | ||
804 | ), | ||
805 | edit: TextEdit { | ||
806 | indels: [ | ||
807 | Indel { | ||
808 | insert: "foo2", | ||
809 | delete: 27..30, | ||
810 | }, | ||
811 | ], | ||
812 | }, | ||
813 | }, | ||
814 | ], | ||
815 | file_system_edits: [ | ||
816 | MoveFile { | ||
817 | src: FileId( | ||
818 | 3, | ||
819 | ), | ||
820 | anchor: FileId( | ||
821 | 2, | ||
822 | ), | ||
823 | dst: "foo2.rs", | ||
824 | }, | ||
825 | ], | ||
826 | is_snippet: false, | ||
827 | }, | ||
828 | } | ||
829 | "#]], | ||
785 | ); | 830 | ); |
786 | } | 831 | } |
787 | 832 | ||
@@ -791,9 +836,7 @@ pub mod foo<|>; | |||
791 | "Baz", | 836 | "Baz", |
792 | r#" | 837 | r#" |
793 | mod foo { | 838 | mod foo { |
794 | pub enum Foo { | 839 | pub enum Foo { Bar<|> } |
795 | Bar<|>, | ||
796 | } | ||
797 | } | 840 | } |
798 | 841 | ||
799 | fn func(f: foo::Foo) { | 842 | fn func(f: foo::Foo) { |
@@ -804,9 +847,7 @@ fn func(f: foo::Foo) { | |||
804 | "#, | 847 | "#, |
805 | r#" | 848 | r#" |
806 | mod foo { | 849 | mod foo { |
807 | pub enum Foo { | 850 | pub enum Foo { Baz } |
808 | Baz, | ||
809 | } | ||
810 | } | 851 | } |
811 | 852 | ||
812 | fn func(f: foo::Foo) { | 853 | fn func(f: foo::Foo) { |