mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 20:09:19 +00:00
Simplify
This commit is contained in:
parent
d571ca814e
commit
3fab50019c
4 changed files with 10 additions and 12 deletions
|
@ -24,6 +24,7 @@ use crate::{
|
||||||
FilePosition, Semantics,
|
FilePosition, Semantics,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Weblink to an item's documentation.
|
||||||
pub(crate) type DocumentationLink = String;
|
pub(crate) type DocumentationLink = String;
|
||||||
|
|
||||||
/// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs)
|
/// Rewrite documentation links in markdown to point to an online host (e.g. docs.rs)
|
||||||
|
|
|
@ -43,11 +43,10 @@ pub(crate) fn goto_definition(
|
||||||
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)?;
|
||||||
|
|
||||||
let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?;
|
let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?;
|
||||||
let (_, link, ns) =
|
let (_, link, ns) =
|
||||||
extract_definitions_from_docs(&docs).into_iter().find(|(range, ..)| {
|
extract_definitions_from_docs(&docs).into_iter().find(|&(range, ..)| {
|
||||||
doc_mapping.map(*range).map_or(false, |InFile { file_id, value: range }| {
|
doc_mapping.map(range).map_or(false, |InFile { file_id, value: range }| {
|
||||||
file_id == position.file_id.into() && range.contains(position.offset)
|
file_id == position.file_id.into() && range.contains(position.offset)
|
||||||
})
|
})
|
||||||
})?;
|
})?;
|
||||||
|
|
|
@ -120,12 +120,8 @@ pub(crate) fn hover(
|
||||||
let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?;
|
let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?;
|
||||||
let (idl_range, link, ns) =
|
let (idl_range, link, ns) =
|
||||||
extract_definitions_from_docs(&docs).into_iter().find_map(|(range, link, ns)| {
|
extract_definitions_from_docs(&docs).into_iter().find_map(|(range, link, ns)| {
|
||||||
let hir::InFile { file_id, value: range } = doc_mapping.map(range)?;
|
let hir::InFile { file_id, value: mapped_range } = doc_mapping.map(range)?;
|
||||||
if file_id == position.file_id.into() && range.contains(position.offset) {
|
(file_id == position.file_id.into() && mapped_range.contains(position.offset)).then(||(mapped_range, link, ns))
|
||||||
Some((range, link, ns))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})?;
|
})?;
|
||||||
range = Some(idl_range);
|
range = Some(idl_range);
|
||||||
resolve_doc_path_for_def(db, def, &link, ns).map(Definition::ModuleDef)
|
resolve_doc_path_for_def(db, def, &link, ns).map(Definition::ModuleDef)
|
||||||
|
|
|
@ -107,9 +107,11 @@ pub(super) fn doc_comment(
|
||||||
extract_definitions_from_docs(&docs)
|
extract_definitions_from_docs(&docs)
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter_map(|(range, link, ns)| {
|
.filter_map(|(range, link, ns)| {
|
||||||
let def = resolve_doc_path_for_def(sema.db, def, &link, ns)?;
|
doc_mapping.map(range).filter(|mapping| mapping.file_id == node.file_id).and_then(
|
||||||
let InFile { file_id, value: range } = doc_mapping.map(range)?;
|
|InFile { value: mapped_range, .. }| {
|
||||||
(file_id == node.file_id).then(|| (range, def))
|
Some(mapped_range).zip(resolve_doc_path_for_def(sema.db, def, &link, ns))
|
||||||
|
},
|
||||||
|
)
|
||||||
})
|
})
|
||||||
.for_each(|(range, def)| {
|
.for_each(|(range, def)| {
|
||||||
hl.add(HlRange {
|
hl.add(HlRange {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue