mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 13:51:31 +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,5 +1,5 @@
|
|||
use either::Either;
|
||||
use hir::Semantics;
|
||||
use hir::{InFile, Semantics};
|
||||
use ide_db::{
|
||||
defs::{NameClass, NameRefClass},
|
||||
RootDatabase,
|
||||
|
@ -8,7 +8,7 @@ use syntax::{ast, match_ast, AstNode, AstToken, SyntaxKind::*, SyntaxToken, Toke
|
|||
|
||||
use crate::{
|
||||
display::TryToNav,
|
||||
doc_links::{doc_owner_to_def, extract_positioned_link_from_comment, resolve_doc_path_for_def},
|
||||
doc_links::{doc_attributes, extract_definitions_from_markdown, resolve_doc_path_for_def},
|
||||
FilePosition, NavigationTarget, RangeInfo,
|
||||
};
|
||||
|
||||
|
@ -30,11 +30,16 @@ pub(crate) fn goto_definition(
|
|||
let original_token = pick_best(file.token_at_offset(position.offset))?;
|
||||
let token = sema.descend_into_macros(original_token.clone());
|
||||
let parent = token.parent()?;
|
||||
if let Some(comment) = ast::Comment::cast(token) {
|
||||
let docs = doc_owner_to_def(&sema, &parent)?.docs(db)?;
|
||||
if let Some(_) = ast::Comment::cast(token) {
|
||||
let (attributes, def) = doc_attributes(&sema, &parent)?;
|
||||
|
||||
let (_, link, ns) = extract_positioned_link_from_comment(position.offset, &comment, docs)?;
|
||||
let def = doc_owner_to_def(&sema, &parent)?;
|
||||
let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?;
|
||||
let (_, link, ns) =
|
||||
extract_definitions_from_markdown(docs.as_str()).into_iter().find(|(range, ..)| {
|
||||
doc_mapping.map(range.clone()).map_or(false, |InFile { file_id, value: range }| {
|
||||
file_id == position.file_id.into() && range.contains(position.offset)
|
||||
})
|
||||
})?;
|
||||
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]));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue