mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-27 21:43:37 +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,
|
kind if kind.is_trivia() => 0,
|
||||||
_ => 1,
|
_ => 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! {
|
let ty = match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::Expr(it) => sema.type_of_expr(&it)?.original,
|
ast::Expr(it) => sema.type_of_expr(&it)?.original,
|
||||||
|
@ -51,18 +62,12 @@ pub(crate) fn goto_type_definition(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Some((ty, node))
|
Some(ty)
|
||||||
})?;
|
});
|
||||||
|
ty
|
||||||
let mut res = Vec::new();
|
})
|
||||||
let mut push = |def: hir::ModuleDef| {
|
.for_each(|ty| {
|
||||||
if let Some(nav) = def.try_to_nav(db) {
|
// collect from each `ty` into the `res` result vec
|
||||||
if !res.contains(&nav) {
|
|
||||||
res.push(nav);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let ty = ty.strip_references();
|
let ty = ty.strip_references();
|
||||||
ty.walk(db, |t| {
|
ty.walk(db, |t| {
|
||||||
if let Some(adt) = t.as_adt() {
|
if let Some(adt) = t.as_adt() {
|
||||||
|
@ -75,8 +80,12 @@ pub(crate) fn goto_type_definition(
|
||||||
push(trait_.into());
|
push(trait_.into());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
Some(RangeInfo::new(node.text_range(), res))
|
if res.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(RangeInfo::new(range, res))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
Loading…
Reference in a new issue