Address PR comments

This commit is contained in:
Tianyi Song 2022-02-13 18:14:39 +08:00
parent e62e926a8a
commit aa8c982c3a

View File

@ -25,6 +25,7 @@
use base_db::{AnchoredPathBuf, FileId, FileRange};
use either::Either;
use hir::{AsAssocItem, FieldSource, HasSource, InFile, ModuleSource, Semantics};
use stdx::never;
use syntax::{
ast::{self, HasName},
AstNode, SyntaxKind, TextRange, T,
@ -187,13 +188,20 @@ fn rename_mod(
source_change.push_file_system_edit(move_file);
}
if let Some(InFile { file_id, value: _ }) = module.declaration_source(sema.db) {
let file_id = file_id.original_file(sema.db);
if let Some(file_range) = Definition::Module(module).range_for_rename(sema) {
if let Some(src) = module.declaration_source(sema.db) {
let file_id = src.file_id.original_file(sema.db);
match src.value.name() {
Some(name) => {
if let Some(file_range) =
src.with_value(name.syntax()).original_file_range_opt(sema.db)
{
source_change.insert_source_edit(
file_id,
TextEdit::replace(file_range.range, new_name.to_string()),
)
};
}
_ => never!("Module source node is missing a name"),
}
}