diff options
-rw-r--r-- | plugins/base/api/base.api | 29 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt | 45 |
2 files changed, 46 insertions, 28 deletions
diff --git a/plugins/base/api/base.api b/plugins/base/api/base.api index 2ab821d4..526e7ab4 100644 --- a/plugins/base/api/base.api +++ b/plugins/base/api/base.api @@ -460,23 +460,36 @@ public final class org/jetbrains/dokka/base/renderers/html/SearchRecord$Companio public class org/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller : org/jetbrains/dokka/transformers/pages/PageTransformer { public fun <init> (Lorg/jetbrains/dokka/plugability/DokkaContext;)V public fun createSearchRecord (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/List;)Lorg/jetbrains/dokka/base/renderers/html/SearchRecord; - public fun generatePagesList (Ljava/util/List;Lorg/jetbrains/dokka/pages/PageResolver;)Ljava/util/List; + public fun generatePagesList (Ljava/util/List;Lorg/jetbrains/dokka/pages/DriResolver;)Ljava/util/List; public final fun getContext ()Lorg/jetbrains/dokka/plugability/DokkaContext; public fun invoke (Lorg/jetbrains/dokka/pages/RootPageNode;)Lorg/jetbrains/dokka/pages/RootPageNode; public fun processPage (Lorg/jetbrains/dokka/pages/PageNode;)Ljava/util/List; } -public final class org/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$PageWithId { - public fun <init> (Lorg/jetbrains/dokka/links/DRI;Lorg/jetbrains/dokka/pages/ContentPage;)V +public final class org/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$DRIWithSourceSets { + public fun <init> (Lorg/jetbrains/dokka/links/DRI;Ljava/util/Set;)V public final fun component1 ()Lorg/jetbrains/dokka/links/DRI; - public final fun component2 ()Lorg/jetbrains/dokka/pages/ContentPage; - public final fun copy (Lorg/jetbrains/dokka/links/DRI;Lorg/jetbrains/dokka/pages/ContentPage;)Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$PageWithId; - public static synthetic fun copy$default (Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$PageWithId;Lorg/jetbrains/dokka/links/DRI;Lorg/jetbrains/dokka/pages/ContentPage;ILjava/lang/Object;)Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$PageWithId; + public final fun component2 ()Ljava/util/Set; + public final fun copy (Lorg/jetbrains/dokka/links/DRI;Ljava/util/Set;)Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$DRIWithSourceSets; + public static synthetic fun copy$default (Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$DRIWithSourceSets;Lorg/jetbrains/dokka/links/DRI;Ljava/util/Set;ILjava/lang/Object;)Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$DRIWithSourceSets; public fun equals (Ljava/lang/Object;)Z - public final fun getDisplayableSignature ()Ljava/lang/String; public final fun getDri ()Lorg/jetbrains/dokka/links/DRI; + public final fun getSourceSet ()Ljava/util/Set; + public fun hashCode ()I + public fun toString ()Ljava/lang/String; +} + +public final class org/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$SignatureWithId { + public fun <init> (Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$DRIWithSourceSets;Ljava/lang/String;)V + public fun <init> (Lorg/jetbrains/dokka/links/DRI;Lorg/jetbrains/dokka/pages/ContentPage;)V + public final fun component1 ()Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$DRIWithSourceSets; + public final fun component2 ()Ljava/lang/String; + public final fun copy (Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$DRIWithSourceSets;Ljava/lang/String;)Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$SignatureWithId; + public static synthetic fun copy$default (Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$SignatureWithId;Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$DRIWithSourceSets;Ljava/lang/String;ILjava/lang/Object;)Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$SignatureWithId; + public fun equals (Ljava/lang/Object;)Z + public final fun getDisplayableSignature ()Ljava/lang/String; + public final fun getDriWithSourceSets ()Lorg/jetbrains/dokka/base/renderers/html/SearchbarDataInstaller$DRIWithSourceSets; public final fun getId ()Ljava/lang/String; - public final fun getPage ()Lorg/jetbrains/dokka/pages/ContentPage; public fun hashCode ()I public fun toString ()Ljava/lang/String; } 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<DisplaySourceSet>) + 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<PageWithId>, locationResolver: PageResolver): List<SearchRecord> = + open fun generatePagesList(pages: List<SignatureWithId>, locationResolver: DriResolver): List<SearchRecord> = 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<PageWithId> = + open fun processPage(page: PageNode): List<SignatureWithId> = 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<SignatureWithId>()) { pageList, page -> + pageList + processPage(page) + } val page = RendererSpecificResourcePage( name = "scripts/pages.json", children = emptyList(), - strategy = RenderingStrategy.PageLocationResolvableWrite { resolver -> - val content = input.withDescendants().fold(emptyList<PageWithId>()) { pageList, page -> - pageList + processPage(page) - }.run { + strategy = RenderingStrategy.DriLocationResolvableWrite { resolver -> + val content = signatureWithIds.run { generatePagesList(this, resolver) } |