Skip to content

Commit db9930b

Browse files
committed
Auto merge of rust-lang#12357 - Veykril:find-ref-macro, r=Veykril
fix: When reference searching macro inputs, don't search everything that was downmapped Fixes rust-lang/rust-analyzer#11668
2 parents 238253c + 377c924 commit db9930b

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

crates/hir/src/semantics.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
208208
self.imp.descend_into_macros(token)
209209
}
210210

211-
/// Descend the token into macrocalls to all its mapped counterparts.
211+
/// Descend the token into macrocalls to all its mapped counterparts that have the same text as the input token.
212212
///
213-
/// Returns the original non descended token if none of the mapped counterparts have the same syntax kind.
214-
pub fn descend_into_macros_with_same_kind(
213+
/// Returns the original non descended token if none of the mapped counterparts have the same text.
214+
pub fn descend_into_macros_with_same_text(
215215
&self,
216216
token: SyntaxToken,
217217
) -> SmallVec<[SyntaxToken; 1]> {
218-
self.imp.descend_into_macros_with_same_kind(token)
218+
self.imp.descend_into_macros_with_same_text(token)
219219
}
220220

221221
/// Maps a node down by mapping its first and last token down.
@@ -666,11 +666,11 @@ impl<'db> SemanticsImpl<'db> {
666666
res
667667
}
668668

669-
fn descend_into_macros_with_same_kind(&self, token: SyntaxToken) -> SmallVec<[SyntaxToken; 1]> {
670-
let kind = token.kind();
669+
fn descend_into_macros_with_same_text(&self, token: SyntaxToken) -> SmallVec<[SyntaxToken; 1]> {
670+
let text = token.text();
671671
let mut res = smallvec![];
672672
self.descend_into_macros_impl(token.clone(), &mut |InFile { value, .. }| {
673-
if value.kind() == kind {
673+
if value.text() == text {
674674
res.push(value);
675675
}
676676
false

crates/ide/src/hover.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub(crate) fn hover(
115115
});
116116
}
117117

118-
let descended = sema.descend_into_macros(original_token.clone());
118+
let descended = sema.descend_into_macros_with_same_text(original_token.clone());
119119

120120
// FIXME: Definition should include known lints and the like instead of having this special case here
121121
let hovered_lint = descended.iter().find_map(|token| {

crates/ide/src/references.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub(crate) fn find_defs<'a>(
122122
)
123123
});
124124
token.map(|token| {
125-
sema.descend_into_macros_with_same_kind(token)
125+
sema.descend_into_macros_with_same_text(token)
126126
.into_iter()
127127
.filter_map(|it| ast::NameLike::cast(it.parent()?))
128128
.filter_map(move |name_like| {

crates/syntax/src/ast/node_ext.rs

+7
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,13 @@ impl NameLike {
432432
_ => None,
433433
}
434434
}
435+
pub fn text(&self) -> TokenText {
436+
match self {
437+
NameLike::NameRef(name_ref) => name_ref.text(),
438+
NameLike::Name(name) => name.text(),
439+
NameLike::Lifetime(lifetime) => lifetime.text(),
440+
}
441+
}
435442
}
436443

437444
impl ast::AstNode for NameLike {

0 commit comments

Comments
 (0)