Skip to content

Commit 25808c1

Browse files
authored
Merge pull request #19893 from Veykril/push-wzqsompmnlmx
Enhance renaming to include identifiers that are generated from the original symbol
2 parents 04439c8 + 9a786d0 commit 25808c1

File tree

9 files changed

+604
-257
lines changed

9 files changed

+604
-257
lines changed

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ smol_str.opt-level = 3
2121
text-size.opt-level = 3
2222
serde.opt-level = 3
2323
salsa.opt-level = 3
24+
dissimilar.opt-level = 3
25+
2426
# This speeds up `cargo xtask dist`.
2527
miniz_oxide.opt-level = 3
2628

crates/hir-def/src/dyn_map.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,14 @@ pub mod keys {
6767
pub const PROC_MACRO: Key<ast::Fn, ProcMacroId> = Key::new();
6868
pub const MACRO_CALL: Key<ast::MacroCall, MacroCallId> = Key::new();
6969
pub const ATTR_MACRO_CALL: Key<ast::Item, MacroCallId> = Key::new();
70-
pub const DERIVE_MACRO_CALL: Key<ast::Attr, (AttrId, MacroCallId, Box<[Option<MacroCallId>]>)> =
71-
Key::new();
70+
pub const DERIVE_MACRO_CALL: Key<
71+
ast::Attr,
72+
(
73+
AttrId,
74+
/* derive() */ MacroCallId,
75+
/* actual derive macros */ Box<[Option<MacroCallId>]>,
76+
),
77+
> = Key::new();
7278

7379
/// XXX: AST Nodes and SyntaxNodes have identity equality semantics: nodes are
7480
/// equal if they point to exactly the same object.

crates/hir/src/semantics.rs

Lines changed: 202 additions & 115 deletions
Large diffs are not rendered by default.

crates/hir/src/semantics/source_to_def.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ use span::FileId;
108108
use stdx::impl_from;
109109
use syntax::{
110110
AstNode, AstPtr, SyntaxNode,
111-
ast::{self, HasName},
111+
ast::{self, HasAttrs, HasName},
112112
};
113113
use tt::TextRange;
114114

@@ -411,10 +411,24 @@ impl SourceToDefCtx<'_, '_> {
411411
.map(|&(attr_id, call_id, ref ids)| (attr_id, call_id, &**ids))
412412
}
413413

414-
pub(super) fn has_derives(&mut self, adt: InFile<&ast::Adt>) -> bool {
414+
pub(super) fn file_of_adt_has_derives(&mut self, adt: InFile<&ast::Adt>) -> bool {
415415
self.dyn_map(adt).as_ref().is_some_and(|map| !map[keys::DERIVE_MACRO_CALL].is_empty())
416416
}
417417

418+
pub(super) fn derive_macro_calls<'slf>(
419+
&'slf mut self,
420+
adt: InFile<&ast::Adt>,
421+
) -> Option<impl Iterator<Item = (AttrId, MacroCallId, &'slf [Option<MacroCallId>])> + use<'slf>>
422+
{
423+
self.dyn_map(adt).as_ref().map(|&map| {
424+
let dyn_map = &map[keys::DERIVE_MACRO_CALL];
425+
adt.value
426+
.attrs()
427+
.filter_map(move |attr| dyn_map.get(&AstPtr::new(&attr)))
428+
.map(|&(attr_id, call_id, ref ids)| (attr_id, call_id, &**ids))
429+
})
430+
}
431+
418432
fn to_def<Ast: AstNode + 'static, ID: Copy + 'static>(
419433
&mut self,
420434
src: InFile<&Ast>,

crates/ide-assists/src/handlers/remove_underscore.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use ide_db::{
22
assists::AssistId,
33
defs::{Definition, NameClass, NameRefClass},
4+
rename::RenameDefinition,
45
};
56
use syntax::{AstNode, ast};
67

@@ -61,7 +62,7 @@ pub(crate) fn remove_underscore(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
6162
"Remove underscore from a used variable",
6263
text_range,
6364
|builder| {
64-
let changes = def.rename(&ctx.sema, new_name).unwrap();
65+
let changes = def.rename(&ctx.sema, new_name, RenameDefinition::Yes).unwrap();
6566
builder.source_change = changes;
6667
},
6768
)

0 commit comments

Comments
 (0)