10252: fix: make `goto_definition` multi-token mapping aware r=Veykril a=XFFXFF

Implement #10070 in  [`goto_definition`](https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide/src/goto_definition.rs)

Co-authored-by: zhoufan <1247714429@qq.com>
This commit is contained in:
bors[bot] 2021-09-18 01:21:43 +00:00 committed by GitHub
commit a435e49d34
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -39,9 +39,8 @@ pub(crate) fn goto_definition(
kind if kind.is_trivia() => 0,
_ => 1,
})?;
let token = sema.descend_into_macros(original_token.clone());
let parent = token.parent()?;
if let Some(_) = ast::Comment::cast(token.clone()) {
if let Some(_) = ast::Comment::cast(original_token.clone()) {
let parent = original_token.parent()?;
let (attributes, def) = doc_attributes(&sema, &parent)?;
let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?;
let (_, link, ns) =
@ -54,6 +53,10 @@ pub(crate) fn goto_definition(
return Some(RangeInfo::new(original_token.text_range(), vec![nav]));
}
let navs = sema.descend_into_macros_many(original_token.clone())
.into_iter()
.filter_map(|token| {
let parent = token.parent()?;
let navs = match_ast! {
match parent {
ast::NameRef(name_ref) => {
@ -81,6 +84,10 @@ pub(crate) fn goto_definition(
_ => return None,
}
};
Some(navs)
})
.flatten()
.collect::<Vec<NavigationTarget>>();
Some(RangeInfo::new(original_token.text_range(), navs))
}