diff options
author | Kamil Doległo <kamilok1965@interia.pl> | 2020-08-27 14:48:54 +0200 |
---|---|---|
committer | Sebastian Sellmair <34319766+sellmair@users.noreply.github.com> | 2020-08-28 16:34:23 +0200 |
commit | 6d00ac775b77ce373a9a8d39eadeec32b155920a (patch) | |
tree | 3b4b48746f7ec127786fcea40fff52a254d3b6d7 /plugins/base/src | |
parent | 9fe95458fff1abf711884abc3ec2f6da1b802a2b (diff) | |
download | dokka-6d00ac775b77ce373a9a8d39eadeec32b155920a.tar.gz dokka-6d00ac775b77ce373a9a8d39eadeec32b155920a.tar.bz2 dokka-6d00ac775b77ce373a9a8d39eadeec32b155920a.zip |
Fix unstable ordering by sorting methods and entries in the searchbar
Diffstat (limited to 'plugins/base/src')
-rw-r--r-- | plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt | 27 | ||||
-rw-r--r-- | plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt | 65 |
2 files changed, 47 insertions, 45 deletions
diff --git a/plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt b/plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt index cd95013a..f953821f 100644 --- a/plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt +++ b/plugins/base/src/main/kotlin/renderers/html/SearchbarDataInstaller.kt @@ -1,20 +1,20 @@ package org.jetbrains.dokka.base.renderers.html -import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.Platform -import org.jetbrains.dokka.base.resolvers.local.LocationProvider import org.jetbrains.dokka.model.DisplaySourceSet import org.jetbrains.dokka.model.dfs import org.jetbrains.dokka.pages.* +import java.util.concurrent.ConcurrentHashMap -class SearchbarDataInstaller() { - private val pageList = mutableMapOf<String, Pair<String, String>>() +class SearchbarDataInstaller { + private val pageList = ConcurrentHashMap<String, Pair<String, String>>() - private fun String.escaped(): String = this.replace("'","\\'") + private fun String.escaped(): String = this.replace("'", "\\'") - fun generatePagesList(): String { - return pageList.entries + fun generatePagesList(): String = + pageList.entries .filter { it.key.isNotEmpty() } + .sortedWith(compareBy({ it.key }, { it.value.first }, { it.value.second })) .groupBy { it.key.substringAfterLast(".") } .entries .flatMapIndexed { topLevelIndex, entry -> @@ -23,7 +23,6 @@ class SearchbarDataInstaller() { } } .joinToString(prefix = "[", separator = ",\n", postfix = "]") - } private fun getSymbolSignature(page: ContentPage) = page.content.dfs { it.dci.kind == ContentKind.Symbol } @@ -54,16 +53,10 @@ class SearchbarDataInstaller() { documentable.dri.packageName, documentable.dri.classNames, documentable.dri.callable?.name - ) - .filter { !it.isNullOrEmpty() } + ).filter { !it.isNullOrEmpty() } .takeIf { it.isNotEmpty() } ?.joinToString(".") - ?.let { - pageList.put(it, Pair(textNodes ?: page.name, link)) - } - + ?.let { id -> pageList.put(id, Pair(textNodes ?: page.name, link)) } } } - - -}
\ No newline at end of file +} diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index 30f35003..3cc77f96 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -88,10 +88,11 @@ open class DefaultPageCreator( val documentations = it.sourceSets.map { platform -> it.descriptions[platform]?.also { it.root } } - val haveSameContent = documentations.all { it?.root == documentations.firstOrNull()?.root && it?.root != null } + val haveSameContent = + documentations.all { it?.root == documentations.firstOrNull()?.root && it?.root != null } link(it.name, it.dri) - if(it.sourceSets.size == 1 || (documentations.isNotEmpty() && haveSameContent)){ + if (it.sourceSets.size == 1 || (documentations.isNotEmpty() && haveSameContent)) { documentations.first()?.let { firstSentenceComment(kind = ContentKind.Comment, content = it) } } } @@ -129,7 +130,7 @@ open class DefaultPageCreator( divergentBlock("Types", types, ContentKind.Classlikes, extra = mainExtra + SimpleAttr.header("Types")) divergentBlock( "Functions", - s.functions, + s.functions.sorted(), ContentKind.Functions, extra = mainExtra + SimpleAttr.header("Functions") ) @@ -153,8 +154,8 @@ open class DefaultPageCreator( if (map.values.any()) { header(2, "Inheritors") { } +ContentTable( - listOf(contentBuilder.contentFor(mainDRI, mainSourcesetData){ - text("Name") + listOf(contentBuilder.contentFor(mainDRI, mainSourcesetData) { + text("Name") }), map.entries.flatMap { entry -> entry.value.map { Pair(entry.key, it) } } .groupBy({ it.second }, { it.first }).map { (classlike, platforms) -> @@ -174,6 +175,9 @@ open class DefaultPageCreator( } } + private fun Iterable<DFunction>.sorted() = + sortedWith(compareBy({ it.name }, { it.parameters.size }, { it.dri.toString() })) + protected open fun contentForEnumEntry(e: DEnumEntry) = contentBuilder.contentFor(e) { group(kind = ContentKind.Cover) { cover(e.name) @@ -246,7 +250,12 @@ open class DefaultPageCreator( } +contentForScope(c, c.dri, c.sourceSets) - divergentBlock("Extensions", extensions, ContentKind.Extensions, extra = mainExtra + SimpleAttr.header("Extensions")) + divergentBlock( + "Extensions", + extensions, + ContentKind.Extensions, + extra = mainExtra + SimpleAttr.header("Extensions") + ) } } @@ -484,36 +493,36 @@ open class DefaultPageCreator( .groupBy { it.name } // This hacks displaying actual typealias signatures along classlike ones .mapValues { if (it.value.any { it is DClasslike }) it.value.filter { it !is DTypeAlias } else it.value } - .toSortedMap(compareBy(nullsLast(String.CASE_INSENSITIVE_ORDER)){it}) + .toSortedMap(compareBy(nullsLast(String.CASE_INSENSITIVE_ORDER)) { it }) .map { (elementName, elements) -> // This groupBy should probably use LocationProvider - buildGroup( - dri = elements.map { it.dri }.toSet(), - sourceSets = elements.flatMap { it.sourceSets }.toSet(), - kind = kind, - styles = emptySet() - ) { - link(elementName.orEmpty(), elements.first().dri, kind = kind) - divergentGroup( - ContentDivergentGroup.GroupID(name), - elements.map { it.dri }.toSet(), - kind = kind + buildGroup( + dri = elements.map { it.dri }.toSet(), + sourceSets = elements.flatMap { it.sourceSets }.toSet(), + kind = kind, + styles = emptySet() ) { - elements.map { - instance(setOf(it.dri), it.sourceSets.toSet()) { - before { - contentForBrief(it) - contentForSinceKotlin(it) - } - divergent { - group { - +buildSignature(it) + link(elementName.orEmpty(), elements.first().dri, kind = kind) + divergentGroup( + ContentDivergentGroup.GroupID(name), + elements.map { it.dri }.toSet(), + kind = kind + ) { + elements.map { + instance(setOf(it.dri), it.sourceSets.toSet()) { + before { + contentForBrief(it) + contentForSinceKotlin(it) + } + divergent { + group { + +buildSignature(it) + } } } } } } } - } } } } |