Skip to content

Commit 2972e77

Browse files
committed
fix: Do not force descend into derives for goto IDE features
Doing so can cause us to duplicate navigation targets for the same ranges which breaks convenience features of some editors where go to def can trigger find all references
1 parent fa7a6c1 commit 2972e77

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

src/tools/rust-analyzer/crates/hir/src/semantics.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<DB: HirDatabase + ?Sized> Semantics<'_, DB> {
244244
offset: TextSize,
245245
) -> impl Iterator<Item = ast::NameLike> + 'slf {
246246
node.token_at_offset(offset)
247-
.map(move |token| self.descend_into_macros_no_opaque(token))
247+
.map(move |token| self.descend_into_macros_no_opaque(token, true))
248248
.map(|descendants| descendants.into_iter().filter_map(move |it| it.value.parent()))
249249
// re-order the tokens from token_at_offset by returning the ancestors with the smaller first nodes first
250250
// See algo::ancestors_at_offset, which uses the same approach
@@ -1009,10 +1009,11 @@ impl<'db> SemanticsImpl<'db> {
10091009
pub fn descend_into_macros_no_opaque(
10101010
&self,
10111011
token: SyntaxToken,
1012+
always_descend_into_derives: bool,
10121013
) -> SmallVec<[InFile<SyntaxToken>; 1]> {
10131014
let mut res = smallvec![];
10141015
let token = self.wrap_token_infile(token);
1015-
self.descend_into_macros_all(token.clone(), true, &mut |t, ctx| {
1016+
self.descend_into_macros_all(token.clone(), always_descend_into_derives, &mut |t, ctx| {
10161017
if !ctx.is_opaque(self.db) {
10171018
// Don't descend into opaque contexts
10181019
res.push(t);

src/tools/rust-analyzer/crates/ide/src/goto_declaration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(crate) fn goto_declaration(
2929
.find(|it| matches!(it.kind(), IDENT | T![self] | T![super] | T![crate] | T![Self]))?;
3030
let range = original_token.text_range();
3131
let info: Vec<NavigationTarget> = sema
32-
.descend_into_macros_no_opaque(original_token)
32+
.descend_into_macros_no_opaque(original_token, false)
3333
.iter()
3434
.filter_map(|token| {
3535
let parent = token.value.parent()?;

src/tools/rust-analyzer/crates/ide/src/goto_definition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub(crate) fn goto_definition(
8888
}
8989

9090
let navs = sema
91-
.descend_into_macros_no_opaque(original_token.clone())
91+
.descend_into_macros_no_opaque(original_token.clone(), false)
9292
.into_iter()
9393
.filter_map(|token| {
9494
let parent = token.value.parent()?;

src/tools/rust-analyzer/crates/ide/src/goto_type_definition.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(crate) fn goto_type_definition(
7070
}
7171

7272
let range = token.text_range();
73-
sema.descend_into_macros_no_opaque(token)
73+
sema.descend_into_macros_no_opaque(token,false)
7474
.into_iter()
7575
.filter_map(|token| {
7676
sema

0 commit comments

Comments
 (0)