fix: ignore renames for crate root

This commit is contained in:
harpsword 2022-07-07 22:25:25 +08:00
parent fee5555cfa
commit 4b3164f129
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 @@ fn check_expect(new_name: &str, ra_fixture: &str, expect: Expect) {
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 @@ macro_rules! submodule {
)
}
#[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);