Skip to content

Commit 9207f8f

Browse files
authored
Fix source links in case of dri clashing (#2676)
1 parent ee8e730 commit 9207f8f

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

plugins/base/src/main/kotlin/transformers/pages/sourcelinks/SourceLinksTransformer.kt

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import org.jetbrains.dokka.transformers.pages.PageTransformer
1818
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
1919
import org.jetbrains.kotlin.resolve.source.getPsi
2020
import org.jetbrains.kotlin.utils.addToStdlib.cast
21-
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
2221
import java.io.File
2322

2423
class SourceLinksTransformer(val context: DokkaContext) : PageTransformer {
@@ -39,7 +38,14 @@ class SourceLinksTransformer(val context: DokkaContext) : PageTransformer {
3938
is WithDocumentables -> {
4039
val sources = node.documentables
4140
.filterIsInstance<WithSources>()
42-
.associate { (it as Documentable).dri to resolveSources(sourceLinks, it) }
41+
.fold(mutableMapOf<DRI, List<Pair<DokkaSourceSet, String>>>()) { acc, documentable ->
42+
val dri = (documentable as Documentable).dri
43+
acc.compute(dri) { _, v ->
44+
val sources = resolveSources(sourceLinks, documentable)
45+
v?.plus(sources) ?: sources
46+
}
47+
acc
48+
}
4349
if (sources.isNotEmpty())
4450
node.modified(content = transformContent(node.content, sources))
4551
else
@@ -102,15 +108,18 @@ class SourceLinksTransformer(val context: DokkaContext) : PageTransformer {
102108
): ContentNode =
103109
contentNode.signatureGroupOrNull()?.let { sg ->
104110
sources[sg.dci.dri.singleOrNull()]?.let { sourceLinks ->
105-
sourceLinks.filter { it.first.sourceSetID in sg.sourceSets.sourceSetIDs }.ifNotEmpty {
106-
sg.copy(children = sg.children + sourceLinks.map {
107-
buildContentLink(
108-
sg.dci.dri.first(),
109-
it.first,
110-
it.second
111-
)
112-
})
113-
}
111+
sourceLinks
112+
.filter { it.first.sourceSetID in sg.sourceSets.sourceSetIDs }
113+
.takeIf { it.isNotEmpty() }
114+
?.let { filteredSourcesLinks ->
115+
sg.copy(children = sg.children + filteredSourcesLinks.map {
116+
buildContentLink(
117+
sg.dci.dri.first(),
118+
it.first,
119+
it.second
120+
)
121+
})
122+
}
114123
}
115124
} ?: when (contentNode) {
116125
is ContentComposite -> contentNode.transformChildren { transformContent(it, sources) }

0 commit comments

Comments
 (0)