mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 05:23:24 +00:00
Merge #10637
10637: fix: make `goto_type_definition` multi-token mapping aware r=Veykril a=spookyvision Co-authored-by: Anatol Ulrich <anatol.ulrich@ferrous-systems.com>
This commit is contained in:
commit
ee1d6cffbf
1 changed files with 49 additions and 40 deletions
|
@ -27,9 +27,20 @@ pub(crate) fn goto_type_definition(
|
|||
kind if kind.is_trivia() => 0,
|
||||
_ => 1,
|
||||
})?;
|
||||
let token: SyntaxToken = sema.descend_into_macros_single(token);
|
||||
|
||||
let (ty, node) = sema.token_ancestors_with_macros(token).find_map(|node| {
|
||||
let mut res = Vec::new();
|
||||
let mut push = |def: hir::ModuleDef| {
|
||||
if let Some(nav) = def.try_to_nav(db) {
|
||||
if !res.contains(&nav) {
|
||||
res.push(nav);
|
||||
}
|
||||
}
|
||||
};
|
||||
let range = token.text_range();
|
||||
sema.descend_into_macros(token)
|
||||
.iter()
|
||||
.filter_map(|token| {
|
||||
let ty = sema.token_ancestors_with_macros(token.clone()).find_map(|node| {
|
||||
let ty = match_ast! {
|
||||
match node {
|
||||
ast::Expr(it) => sema.type_of_expr(&it)?.original,
|
||||
|
@ -51,18 +62,12 @@ pub(crate) fn goto_type_definition(
|
|||
}
|
||||
};
|
||||
|
||||
Some((ty, node))
|
||||
})?;
|
||||
|
||||
let mut res = Vec::new();
|
||||
let mut push = |def: hir::ModuleDef| {
|
||||
if let Some(nav) = def.try_to_nav(db) {
|
||||
if !res.contains(&nav) {
|
||||
res.push(nav);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Some(ty)
|
||||
});
|
||||
ty
|
||||
})
|
||||
.for_each(|ty| {
|
||||
// collect from each `ty` into the `res` result vec
|
||||
let ty = ty.strip_references();
|
||||
ty.walk(db, |t| {
|
||||
if let Some(adt) = t.as_adt() {
|
||||
|
@ -75,8 +80,12 @@ pub(crate) fn goto_type_definition(
|
|||
push(trait_.into());
|
||||
}
|
||||
});
|
||||
|
||||
Some(RangeInfo::new(node.text_range(), res))
|
||||
});
|
||||
if res.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(RangeInfo::new(range, res))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
Loading…
Reference in a new issue