mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 10:13:54 +00:00
Merge #9702
9702: minor: Simplify r=Veykril a=Veykril bors r+ Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
3a59b56324
@ -24,6 +24,7 @@ use crate::{
|
||||
FilePosition, Semantics,
|
||||
};
|
||||
|
||||
/// Weblink to an item's documentation.
|
||||
pub(crate) type DocumentationLink = String;
|
||||
|
||||
/// 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()?;
|
||||
if let Some(_) = ast::Comment::cast(token.clone()) {
|
||||
let (attributes, def) = doc_attributes(&sema, &parent)?;
|
||||
|
||||
let (docs, doc_mapping) = attributes.docs_with_rangemap(db)?;
|
||||
let (_, link, ns) =
|
||||
extract_definitions_from_docs(&docs).into_iter().find(|(range, ..)| {
|
||||
doc_mapping.map(*range).map_or(false, |InFile { file_id, value: range }| {
|
||||
extract_definitions_from_docs(&docs).into_iter().find(|&(range, ..)| {
|
||||
doc_mapping.map(range).map_or(false, |InFile { file_id, value: range }| {
|
||||
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 (idl_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)?;
|
||||
if file_id == position.file_id.into() && range.contains(position.offset) {
|
||||
Some((range, link, ns))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
let hir::InFile { file_id, value: mapped_range } = doc_mapping.map(range)?;
|
||||
(file_id == position.file_id.into() && mapped_range.contains(position.offset)).then(||(mapped_range, link, ns))
|
||||
})?;
|
||||
range = Some(idl_range);
|
||||
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)
|
||||
.into_iter()
|
||||
.filter_map(|(range, link, ns)| {
|
||||
let def = resolve_doc_path_for_def(sema.db, def, &link, ns)?;
|
||||
let InFile { file_id, value: range } = doc_mapping.map(range)?;
|
||||
(file_id == node.file_id).then(|| (range, def))
|
||||
doc_mapping.map(range).filter(|mapping| mapping.file_id == node.file_id).and_then(
|
||||
|InFile { value: mapped_range, .. }| {
|
||||
Some(mapped_range).zip(resolve_doc_path_for_def(sema.db, def, &link, ns))
|
||||
},
|
||||
)
|
||||
})
|
||||
.for_each(|(range, def)| {
|
||||
hl.add(HlRange {
|
||||
|
Loading…
Reference in New Issue
Block a user