9702: minor: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-07-26 18:28:32 +00:00 committed by GitHub
commit 3a59b56324
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 12 deletions

View File

@ -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)

View File

@ -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)
})
})?;

View File

@ -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)

View File

@ -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 {