mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
fix: multi-token mapping aware goto definition
This commit is contained in:
parent
959c7ef563
commit
ea3535cefc
1 changed files with 55 additions and 38 deletions
|
@ -39,7 +39,11 @@ pub(crate) fn goto_definition(
|
||||||
kind if kind.is_trivia() => 0,
|
kind if kind.is_trivia() => 0,
|
||||||
_ => 1,
|
_ => 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()?;
|
let parent = token.parent()?;
|
||||||
if let Some(_) = ast::Comment::cast(token.clone()) {
|
if let Some(_) = ast::Comment::cast(token.clone()) {
|
||||||
let (attributes, def) = doc_attributes(&sema, &parent)?;
|
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)?;
|
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! {
|
let navs = match_ast! {
|
||||||
match parent {
|
match parent {
|
||||||
ast::NameRef(name_ref) => {
|
ast::NameRef(name_ref) => {
|
||||||
|
@ -81,6 +94,10 @@ pub(crate) fn goto_definition(
|
||||||
_ => return None,
|
_ => return None,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Some(navs)
|
||||||
|
})
|
||||||
|
.flatten()
|
||||||
|
.collect::<Vec<NavigationTarget>>();
|
||||||
|
|
||||||
Some(RangeInfo::new(original_token.text_range(), navs))
|
Some(RangeInfo::new(original_token.text_range(), navs))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue