Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix source links in case of dri clashing #2676

Merged
merged 2 commits into from Sep 26, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,15 @@ 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 ->
if (v != null) v + resolveSources(
sourceLinks, documentable
) else resolveSources(sourceLinks, documentable)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (v != null) v + resolveSources(
sourceLinks, documentable
) else resolveSources(sourceLinks, documentable)
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 +109,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