mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +00:00
fix: When reference searching macro inputs, don't search everything that was downmapped
This commit is contained in:
parent
038a71a201
commit
ad537be194
3 changed files with 15 additions and 8 deletions
|
@ -208,14 +208,14 @@ impl<'db, DB: HirDatabase> Semantics<'db, DB> {
|
||||||
self.imp.descend_into_macros(token)
|
self.imp.descend_into_macros(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Descend the token into macrocalls to all its mapped counterparts.
|
/// Descend the token into macrocalls to all its mapped counterparts that have the same text as the input token.
|
||||||
///
|
///
|
||||||
/// Returns the original non descended token if none of the mapped counterparts have the same syntax kind.
|
/// Returns the original non descended token if none of the mapped counterparts have the same text.
|
||||||
pub fn descend_into_macros_with_same_kind(
|
pub fn descend_into_macros_with_same_text(
|
||||||
&self,
|
&self,
|
||||||
token: SyntaxToken,
|
token: SyntaxToken,
|
||||||
) -> SmallVec<[SyntaxToken; 1]> {
|
) -> SmallVec<[SyntaxToken; 1]> {
|
||||||
self.imp.descend_into_macros_with_same_kind(token)
|
self.imp.descend_into_macros_with_same_text(token)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Maps a node down by mapping its first and last token down.
|
/// Maps a node down by mapping its first and last token down.
|
||||||
|
@ -666,11 +666,11 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
res
|
res
|
||||||
}
|
}
|
||||||
|
|
||||||
fn descend_into_macros_with_same_kind(&self, token: SyntaxToken) -> SmallVec<[SyntaxToken; 1]> {
|
fn descend_into_macros_with_same_text(&self, token: SyntaxToken) -> SmallVec<[SyntaxToken; 1]> {
|
||||||
let kind = token.kind();
|
let text = token.text();
|
||||||
let mut res = smallvec![];
|
let mut res = smallvec![];
|
||||||
self.descend_into_macros_impl(token.clone(), &mut |InFile { value, .. }| {
|
self.descend_into_macros_impl(token.clone(), &mut |InFile { value, .. }| {
|
||||||
if value.kind() == kind {
|
if value.text() == text {
|
||||||
res.push(value);
|
res.push(value);
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
|
|
|
@ -122,7 +122,7 @@ pub(crate) fn find_defs<'a>(
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
token.map(|token| {
|
token.map(|token| {
|
||||||
sema.descend_into_macros_with_same_kind(token)
|
sema.descend_into_macros_with_same_text(token)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|it| ast::NameLike::cast(it.parent()?))
|
.filter_map(|it| ast::NameLike::cast(it.parent()?))
|
||||||
.filter_map(move |name_like| {
|
.filter_map(move |name_like| {
|
||||||
|
|
|
@ -432,6 +432,13 @@ impl NameLike {
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn text(&self) -> TokenText {
|
||||||
|
match self {
|
||||||
|
NameLike::NameRef(name_ref) => name_ref.text(),
|
||||||
|
NameLike::Name(name) => name.text(),
|
||||||
|
NameLike::Lifetime(lifetime) => lifetime.text(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ast::AstNode for NameLike {
|
impl ast::AstNode for NameLike {
|
||||||
|
|
Loading…
Reference in a new issue