Skip to content

Commit

Permalink
Fix source links in case of dri clashing (#2676)
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Sep 26, 2022
1 parent ee8e730 commit 9207f8f
Showing 1 changed file with 20 additions and 11 deletions.
Expand Up @@ -18,7 +18,6 @@ import org.jetbrains.dokka.transformers.pages.PageTransformer
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.utils.addToStdlib.cast
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
import java.io.File

class SourceLinksTransformer(val context: DokkaContext) : PageTransformer {
Expand All @@ -39,7 +38,14 @@ class SourceLinksTransformer(val context: DokkaContext) : PageTransformer {
is WithDocumentables -> {
val sources = node.documentables
.filterIsInstance<WithSources>()
.associate { (it as Documentable).dri to resolveSources(sourceLinks, it) }
.fold(mutableMapOf<DRI, List<Pair<DokkaSourceSet, String>>>()) { acc, documentable ->
val dri = (documentable as Documentable).dri
acc.compute(dri) { _, v ->
val sources = resolveSources(sourceLinks, documentable)
v?.plus(sources) ?: sources
}
acc
}
if (sources.isNotEmpty())
node.modified(content = transformContent(node.content, sources))
else
Expand Down Expand Up @@ -102,15 +108,18 @@ class SourceLinksTransformer(val context: DokkaContext) : PageTransformer {
): ContentNode =
contentNode.signatureGroupOrNull()?.let { sg ->
sources[sg.dci.dri.singleOrNull()]?.let { sourceLinks ->
sourceLinks.filter { it.first.sourceSetID in sg.sourceSets.sourceSetIDs }.ifNotEmpty {
sg.copy(children = sg.children + sourceLinks.map {
buildContentLink(
sg.dci.dri.first(),
it.first,
it.second
)
})
}
sourceLinks
.filter { it.first.sourceSetID in sg.sourceSets.sourceSetIDs }
.takeIf { it.isNotEmpty() }
?.let { filteredSourcesLinks ->
sg.copy(children = sg.children + filteredSourcesLinks.map {
buildContentLink(
sg.dci.dri.first(),
it.first,
it.second
)
})
}
}
} ?: when (contentNode) {
is ContentComposite -> contentNode.transformChildren { transformContent(it, sources) }
Expand Down

0 comments on commit 9207f8f

Please sign in to comment.