Skip to content

Fix alias renaming usage #13500

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions crates/ide-db/src/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fn rename_mod(
let def = Definition::Module(module);
let usages = def.usages(sema).all();
let ref_edits = usages.iter().map(|(&file_id, references)| {
(file_id, source_edit_from_references(references, def, new_name))
(file_id, source_edit_from_references(sema, references, def, new_name))
});
source_change.extend(ref_edits);

Expand Down Expand Up @@ -291,7 +291,7 @@ fn rename_reference(
}
let mut source_change = SourceChange::default();
source_change.extend(usages.iter().map(|(&file_id, references)| {
(file_id, source_edit_from_references(references, def, new_name))
(file_id, source_edit_from_references(sema, references, def, new_name))
}));

let mut insert_def_edit = |def| {
Expand All @@ -310,6 +310,7 @@ fn rename_reference(
}

pub fn source_edit_from_references(
sema: &Semantics<'_, RootDatabase>,
references: &[FileReference],
def: Definition,
new_name: &str,
Expand All @@ -325,6 +326,14 @@ pub fn source_edit_from_references(
continue;
}
let has_emitted_edit = match name {
// if the name differs from the definitions name it has to be an alias
ast::NameLike::NameRef(name_ref)
if def
.name(sema.db)
.map_or(false, |it| it.to_smol_str() != name_ref.text().as_str()) =>
{
continue
}
// if the ranges differ then the node is inside a macro call, we can't really attempt
// to make special rewrites like shorthand syntax and such, so just rename the node in
// the macro input
Expand Down
4 changes: 2 additions & 2 deletions crates/ide/src/rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fn rename_to_self(
let usages = def.usages(sema).all();
let mut source_change = SourceChange::default();
source_change.extend(usages.iter().map(|(&file_id, references)| {
(file_id, source_edit_from_references(references, def, "self"))
(file_id, source_edit_from_references(sema, references, def, "self"))
}));
source_change.insert_source_edit(
file_id.original_file(sema.db),
Expand Down Expand Up @@ -298,7 +298,7 @@ fn rename_self_to_param(
let mut source_change = SourceChange::default();
source_change.insert_source_edit(file_id.original_file(sema.db), edit);
source_change.extend(usages.iter().map(|(&file_id, references)| {
(file_id, source_edit_from_references(references, def, new_name))
(file_id, source_edit_from_references(sema, references, def, new_name))
}));
Ok(source_change)
}
Expand Down