diff --git a/crates/ide_db/src/rename.rs b/crates/ide_db/src/rename.rs index cf511feb155..404e17c022b 100644 --- a/crates/ide_db/src/rename.rs +++ b/crates/ide_db/src/rename.rs @@ -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) { - source_change.insert_source_edit( - file_id, - TextEdit::replace(file_range.range, new_name.to_string()), - ) + 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"), } }