Fix module renaming

This commit is contained in:
Aleksey Kladov 2020-07-03 18:45:18 +02:00
parent 4c347a9f65
commit f4a3bc30b8

View file

@ -116,8 +116,7 @@ fn rename_mod(
} else { } else {
format!("{}.rs", new_name) format!("{}.rs", new_name)
}; };
let move_file = let move_file = FileSystemEdit::MoveFile { src: file_id, anchor: file_id, dst };
FileSystemEdit::MoveFile { src: file_id, anchor: position.file_id, dst };
file_system_edits.push(move_file); file_system_edits.push(move_file);
} }
ModuleSource::Module(..) => {} ModuleSource::Module(..) => {}
@ -621,7 +620,7 @@ mod foo<|>;
3, 3,
), ),
anchor: FileId( anchor: FileId(
2, 3,
), ),
dst: "foo2.rs", dst: "foo2.rs",
}, },
@ -687,7 +686,7 @@ use crate::foo<|>::FooContent;
2, 2,
), ),
anchor: FileId( anchor: FileId(
3, 2,
), ),
dst: "quux.rs", dst: "quux.rs",
}, },
@ -734,7 +733,7 @@ mod fo<|>o;
2, 2,
), ),
anchor: FileId( anchor: FileId(
1, 2,
), ),
dst: "../foo2/mod.rs", dst: "../foo2/mod.rs",
}, },
@ -746,6 +745,54 @@ mod fo<|>o;
); );
} }
#[test]
fn test_rename_unusually_nested_mod() {
check_expect(
"bar",
r#"
//- /lib.rs
mod outer { mod fo<|>o; }
//- /outer/foo.rs
// emtpy
"#,
expect![[r#"
RangeInfo {
range: 16..19,
info: SourceChange {
source_file_edits: [
SourceFileEdit {
file_id: FileId(
1,
),
edit: TextEdit {
indels: [
Indel {
insert: "bar",
delete: 16..19,
},
],
},
},
],
file_system_edits: [
MoveFile {
src: FileId(
2,
),
anchor: FileId(
2,
),
dst: "bar.rs",
},
],
is_snippet: false,
},
}
"#]],
);
}
#[test] #[test]
fn test_module_rename_in_path() { fn test_module_rename_in_path() {
check( check(
@ -818,7 +865,7 @@ pub mod foo<|>;
3, 3,
), ),
anchor: FileId( anchor: FileId(
2, 3,
), ),
dst: "foo2.rs", dst: "foo2.rs",
}, },