mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-28 05:53:45 +00:00
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:
commit
ac526e029a
2 changed files with 33 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue