Auto merge of #12712 - harpsword:fix-rename-crate-root, r=Veykril

fix: ignore renames for crate root

close #12684 . I just ignore renames for crate root in `rename_mod` func.
This commit is contained in:
bors 2022-07-16 16:28:41 +00:00
commit ac526e029a
2 changed files with 33 additions and 0 deletions

View file

@ -177,6 +177,10 @@ fn rename_mod(
let mut source_change = SourceChange::default();
if module.is_crate_root(sema.db) {
return Ok(source_change);
}
let InFile { file_id, value: def_source } = module.definition_source(sema.db);
if let ModuleSource::SourceFile(..) = def_source {
let anchor = file_id.original_file(sema.db);

View file

@ -379,6 +379,15 @@ mod tests {
expect.assert_debug_eq(&source_change)
}
fn check_expect_will_rename_file(new_name: &str, ra_fixture: &str, expect: Expect) {
let (analysis, position) = fixture::position(ra_fixture);
let source_change = analysis
.will_rename_file(position.file_id, new_name)
.unwrap()
.expect("Expect returned a RenameError");
expect.assert_debug_eq(&source_change)
}
fn check_prepare(ra_fixture: &str, expect: Expect) {
let (analysis, position) = fixture::position(ra_fixture);
let result = analysis
@ -1245,6 +1254,26 @@ submodule!(bar);
)
}
#[test]
fn test_rename_mod_for_crate_root() {
check_expect_will_rename_file(
"main",
r#"
//- /lib.rs
use crate::foo as bar;
fn foo() {}
mod bar$0;
"#,
expect![[r#"
SourceChange {
source_file_edits: {},
file_system_edits: [],
is_snippet: false,
}
"#]],
)
}
#[test]
fn test_enum_variant_from_module_1() {
cov_mark::check!(rename_non_local);