fix: multi-token mapping aware goto definition
@@ -39,7 +39,11 @@ pub(crate) fn goto_definition(
kind if kind.is_trivia() => 0,
_ => 1,
})?;
- let token = sema.descend_into_macros(original_token.clone());
+ let tokens = sema.descend_into_macros_many(original_token.clone());
+ let navs = tokens
+ .clone()
+ .into_iter()
+ .filter_map(|token| {
let parent = token.parent()?;
if let Some(_) = ast::Comment::cast(token.clone()) {
let (attributes, def) = doc_attributes(&sema, &parent)?;
@@ -51,9 +55,18 @@ pub(crate) fn goto_definition(
})
})?;
let nav = resolve_doc_path_for_def(db, def, &link, ns)?.try_to_nav(db)?;
- return Some(RangeInfo::new(original_token.text_range(), vec![nav]));
+ return Some(nav);
}
-
+ None
+ })
+ .collect::<Vec<NavigationTarget>>();
+ if navs.len() > 0 {
+ return Some(RangeInfo::new(original_token.text_range(), navs));
+ }
+ let navs = tokens
+ .into_iter()
+ .filter_map(|token| {
+ let parent = token.parent()?;
let navs = match_ast! {
match parent {
ast::NameRef(name_ref) => {
@@ -81,6 +94,10 @@ pub(crate) fn goto_definition(
_ => return None,
}
};
+ Some(navs)
+ })
+ .flatten()
+ .collect::<Vec<NavigationTarget>>();
Some(RangeInfo::new(original_token.text_range(), navs))
}
