From aa8c982c3a989672e59e2f9ca01dcac4afc668b3 Mon Sep 17 00:00:00 2001 From: Tianyi Song <42670338+tysg@users.noreply.github.com> Date: Sun, 13 Feb 2022 18:14:39 +0800 Subject: [PATCH] Address PR comments --- crates/ide_db/src/rename.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) 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"), } }