Skip to content

Commit f4a3bc3

Browse files
committed
Fix module renaming
1 parent 4c347a9 commit f4a3bc3

File tree

1 file changed

+53
-6
lines changed

1 file changed

+53
-6
lines changed

crates/ra_ide/src/references/rename.rs

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ fn rename_mod(
116116
} else {
117117
format!("{}.rs", new_name)
118118
};
119-
let move_file =
120-
FileSystemEdit::MoveFile { src: file_id, anchor: position.file_id, dst };
119+
let move_file = FileSystemEdit::MoveFile { src: file_id, anchor: file_id, dst };
121120
file_system_edits.push(move_file);
122121
}
123122
ModuleSource::Module(..) => {}
@@ -621,7 +620,7 @@ mod foo<|>;
621620
3,
622621
),
623622
anchor: FileId(
624-
2,
623+
3,
625624
),
626625
dst: "foo2.rs",
627626
},
@@ -687,7 +686,7 @@ use crate::foo<|>::FooContent;
687686
2,
688687
),
689688
anchor: FileId(
690-
3,
689+
2,
691690
),
692691
dst: "quux.rs",
693692
},
@@ -734,7 +733,7 @@ mod fo<|>o;
734733
2,
735734
),
736735
anchor: FileId(
737-
1,
736+
2,
738737
),
739738
dst: "../foo2/mod.rs",
740739
},
@@ -746,6 +745,54 @@ mod fo<|>o;
746745
);
747746
}
748747

748+
#[test]
749+
fn test_rename_unusually_nested_mod() {
750+
check_expect(
751+
"bar",
752+
r#"
753+
//- /lib.rs
754+
mod outer { mod fo<|>o; }
755+
756+
//- /outer/foo.rs
757+
// emtpy
758+
"#,
759+
expect![[r#"
760+
RangeInfo {
761+
range: 16..19,
762+
info: SourceChange {
763+
source_file_edits: [
764+
SourceFileEdit {
765+
file_id: FileId(
766+
1,
767+
),
768+
edit: TextEdit {
769+
indels: [
770+
Indel {
771+
insert: "bar",
772+
delete: 16..19,
773+
},
774+
],
775+
},
776+
},
777+
],
778+
file_system_edits: [
779+
MoveFile {
780+
src: FileId(
781+
2,
782+
),
783+
anchor: FileId(
784+
2,
785+
),
786+
dst: "bar.rs",
787+
},
788+
],
789+
is_snippet: false,
790+
},
791+
}
792+
"#]],
793+
);
794+
}
795+
749796
#[test]
750797
fn test_module_rename_in_path() {
751798
check(
@@ -818,7 +865,7 @@ pub mod foo<|>;
818865
3,
819866
),
820867
anchor: FileId(
821-
2,
868+
3,
822869
),
823870
dst: "foo2.rs",
824871
},

0 commit comments

Comments
 (0)