From 7e3f6b256585a8592e32ab9d8e01161f32e33aa6 Mon Sep 17 00:00:00 2001 From: vmishenev Date: Fri, 1 Oct 2021 15:36:25 +0300 Subject: Fix keeping irrelevant root page in `SearchbarDataInstaller` --- .../renderers/html/SearchbarDataInstaller.kt | 45 ++++++++++++---------- 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'plugins/base/src') diff --git a/plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt b/plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt index 4d494c82..d8595863 100644 --- a/plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt +++ b/plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka.base.renderers.html import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import org.jetbrains.dokka.Platform +import org.jetbrains.dokka.base.renderers.sourceSets import org.jetbrains.dokka.base.templating.AddToSearch import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.DisplaySourceSet @@ -11,8 +12,6 @@ import org.jetbrains.dokka.pages.* import org.jetbrains.dokka.plugability.DokkaContext import org.jetbrains.dokka.transformers.pages.PageTransformer -typealias PageId = String - data class SearchRecord( val name: String, val description: String? = null, @@ -23,24 +22,29 @@ data class SearchRecord( } open class SearchbarDataInstaller(val context: DokkaContext) : PageTransformer { - data class PageWithId(val dri: DRI, val page: ContentPage) { - val displayableSignature = getSymbolSignature(page, dri)?.let { flattenToText(it) } ?: page.name + data class DRIWithSourceSets(val dri: DRI, val sourceSet: Set) + data class SignatureWithId(val driWithSourceSets: DRIWithSourceSets, val displayableSignature: String) { + constructor(dri: DRI, page: ContentPage) : this( DRIWithSourceSets(dri, page.sourceSets()), + getSymbolSignature(page, dri)?.let { flattenToText(it) } ?: page.name) + val id: String - get() = listOfNotNull( - dri.packageName, - dri.classNames, - dri.callable?.name - ).joinToString(".") + get() = with(driWithSourceSets.dri) { + listOfNotNull( + packageName, + classNames, + callable?.name + ).joinToString(".") + } } private val mapper = jacksonObjectMapper() - open fun generatePagesList(pages: List, locationResolver: PageResolver): List = + open fun generatePagesList(pages: List, locationResolver: DriResolver): List = pages.map { pageWithId -> createSearchRecord( name = pageWithId.displayableSignature, description = pageWithId.id, - location = resolveLocation(locationResolver, pageWithId.page).orEmpty(), + location = resolveLocation(locationResolver, pageWithId.driWithSourceSets).orEmpty(), searchKeys = listOf( pageWithId.id.substringAfterLast("."), pageWithId.displayableSignature, @@ -57,26 +61,27 @@ open class SearchbarDataInstaller(val context: DokkaContext) : PageTransformer { ): SearchRecord = SearchRecord(name, description, location, searchKeys) - open fun processPage(page: PageNode): List = + open fun processPage(page: PageNode): List = when (page) { is ContentPage -> page.takeIf { page !is ModulePageNode && page !is PackagePageNode }?.dri - ?.map { dri -> PageWithId(dri, page) }.orEmpty() + ?.map { dri -> SignatureWithId(dri, page) }.orEmpty() else -> emptyList() } - private fun resolveLocation(locationResolver: PageResolver, page: ContentPage): String? = - locationResolver(page, null).also { location -> - if (location.isNullOrBlank()) context.logger.warn("Cannot resolve path for ${page.dri}") + private fun resolveLocation(locationResolver: DriResolver, driWithSourceSets: DRIWithSourceSets): String? = + locationResolver(driWithSourceSets.dri, driWithSourceSets.sourceSet).also { location -> + if (location.isNullOrBlank()) context.logger.warn("Cannot resolve path for ${driWithSourceSets.dri}") } override fun invoke(input: RootPageNode): RootPageNode { + val signatureWithIds = input.withDescendants().fold(emptyList()) { pageList, page -> + pageList + processPage(page) + } val page = RendererSpecificResourcePage( name = "scripts/pages.json", children = emptyList(), - strategy = RenderingStrategy.PageLocationResolvableWrite { resolver -> - val content = input.withDescendants().fold(emptyList()) { pageList, page -> - pageList + processPage(page) - }.run { + strategy = RenderingStrategy.DriLocationResolvableWrite { resolver -> + val content = signatureWithIds.run { generatePagesList(this, resolver) } -- cgit