mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Use new new docs string source mapping in goto_def and hover
This commit is contained in:
parent
9a327311e4
commit
bb56b7a75c
4 changed files with 72 additions and 118 deletions
|
@ -1,6 +1,6 @@
|
|||
use either::Either;
|
||||
use hir::{
|
||||
AsAssocItem, AssocItemContainer, GenericParam, HasAttrs, HasSource, HirDisplay, Module,
|
||||
AsAssocItem, AssocItemContainer, GenericParam, HasAttrs, HasSource, HirDisplay, InFile, Module,
|
||||
ModuleDef, Semantics,
|
||||
};
|
||||
use ide_db::{
|
||||
|
@ -16,8 +16,8 @@ use syntax::{ast, match_ast, AstNode, AstToken, SyntaxKind::*, SyntaxToken, Toke
|
|||
use crate::{
|
||||
display::{macro_label, TryToNav},
|
||||
doc_links::{
|
||||
doc_owner_to_def, extract_positioned_link_from_comment, remove_links,
|
||||
resolve_doc_path_for_def, rewrite_links,
|
||||
doc_attributes, extract_definitions_from_markdown, remove_links, resolve_doc_path_for_def,
|
||||
rewrite_links,
|
||||
},
|
||||
markdown_remove::remove_markdown,
|
||||
markup::Markup,
|
||||
|
@ -114,11 +114,18 @@ pub(crate) fn hover(
|
|||
),
|
||||
|
||||
_ => ast::Comment::cast(token.clone())
|
||||
.and_then(|comment| {
|
||||
let def = doc_owner_to_def(&sema, &node)?;
|
||||
let docs = def.docs(db)?;
|
||||
.and_then(|_| {
|
||||
let (attributes, def) = doc_attributes(&sema, &node)?;
|
||||
let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?;
|
||||
let (idl_range, link, ns) =
|
||||
extract_positioned_link_from_comment(position.offset, &comment, docs)?;
|
||||
extract_definitions_from_markdown(docs.as_str()).into_iter().find_map(|(range, link, ns)| {
|
||||
let InFile { file_id, value: range } = doc_mapping.map(range.clone())?;
|
||||
if file_id == position.file_id.into() && range.contains(position.offset) {
|
||||
Some((range, link, ns))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})?;
|
||||
range = Some(idl_range);
|
||||
resolve_doc_path_for_def(db, def, &link, ns)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue