do comment handling on the original token

This commit is contained in:
zhoufan 2021-09-18 08:22:57 +08:00
parent ea3535cefc
commit 227450f9b9

View file

@ -39,13 +39,8 @@ pub(crate) fn goto_definition(
kind if kind.is_trivia() => 0, kind if kind.is_trivia() => 0,
_ => 1, _ => 1,
})?; })?;
let tokens = sema.descend_into_macros_many(original_token.clone()); if let Some(_) = ast::Comment::cast(original_token.clone()) {
let navs = tokens let parent = original_token.parent()?;
.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)?; let (attributes, def) = doc_attributes(&sema, &parent)?;
let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?; let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?;
let (_, link, ns) = let (_, link, ns) =
@ -55,15 +50,10 @@ 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(nav); return Some(RangeInfo::new(original_token.text_range(), vec![nav]));
} }
None
}) let navs = sema.descend_into_macros_many(original_token.clone())
.collect::<Vec<NavigationTarget>>();
if navs.len() > 0 {
return Some(RangeInfo::new(original_token.text_range(), navs));
}
let navs = tokens
.into_iter() .into_iter()
.filter_map(|token| { .filter_map(|token| {
let parent = token.parent()?; let parent = token.parent()?;