From 8e313553a3435042cdf295d7436b01af4ea4938a Mon Sep 17 00:00:00 2001 From: Vadim Mishenev Date: Tue, 28 Feb 2023 17:26:10 +0200 Subject: Fix unresolved link to declaration from another source set (#2878) --- .../resolvers/local/DokkaLocationProvider.kt | 27 +++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'plugins/base/src/main/kotlin') diff --git a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt index cae0ccaf..4934e8f4 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DokkaLocationProvider.kt @@ -89,24 +89,35 @@ open class DokkaLocationProvider( private fun getLocalLocation(driWithSourceSets: DRIWithSourceSets, context: PageNode?): String? { val (dri, originalSourceSet) = driWithSourceSets - val allSourceSets = + val allSourceSets: List> = listOf(originalSourceSet) + originalSourceSet.let { oss -> dokkaContext.configuration.sourceSets.filter { it.sourceSetID in oss.sourceSetIDs } .flatMap { it.dependentSourceSets } .mapNotNull { ssid -> dokkaContext.configuration.sourceSets.find { it.sourceSetID == ssid }?.toDisplaySourceSet() + }.map { + // be careful `data DisplaySourceSet: Set` but `setOf(someDisplaySourceSet) != someDisplaySourceSet` + setOf(it) } } - return allSourceSets.asSequence().mapNotNull { displaySourceSet -> - pagesIndex[DRIWithSourceSets(dri, displaySourceSet)]?.let { page -> resolve(page, context) } - ?: anchorsIndex[driWithSourceSets]?.let { (page, kind) -> - val dci = DCI(setOf(dri), kind) - resolve(page, context) + "#" + anchorForDCI(dci, displaySourceSet) - } - }.firstOrNull() + return getLocalPageLink(dri, allSourceSets, context) + ?: getLocalAnchor(dri, allSourceSets, context) } + private fun getLocalPageLink(dri: DRI, allSourceSets: Iterable>, context: PageNode?) = + allSourceSets.mapNotNull { displaySourceSet -> + pagesIndex[DRIWithSourceSets(dri, displaySourceSet)] + }.firstOrNull()?.let { page -> resolve(page, context) } + + private fun getLocalAnchor(dri: DRI, allSourceSets: Iterable>, context: PageNode?) = + allSourceSets.mapNotNull { displaySourceSet -> + anchorsIndex[DRIWithSourceSets(dri, displaySourceSet)]?.let { (page, kind) -> + val dci = DCI(setOf(dri), kind) + resolve(page, context) + "#" + anchorForDCI(dci, displaySourceSet) + } + }.firstOrNull() + override fun pathToRoot(from: PageNode): String = pathTo(pageGraphRoot, from).removeSuffix(PAGE_WITH_CHILDREN_SUFFIX) -- cgit