diff options
author | Paweł Marks <pmarks@virtuslab.com> | 2020-07-06 10:08:43 +0200 |
---|---|---|
committer | Paweł Marks <Kordyjan@users.noreply.github.com> | 2020-07-07 13:23:26 +0200 |
commit | 9e8455d8a5285bfbdd92cab1515270f695a9b5d3 (patch) | |
tree | ccd79e5b5cdb533dbb62e8de63930b5a6adbb851 /plugins/base | |
parent | 2da1f3b1612fd19be8082283c6d070759a42de12 (diff) | |
download | dokka-9e8455d8a5285bfbdd92cab1515270f695a9b5d3.tar.gz dokka-9e8455d8a5285bfbdd92cab1515270f695a9b5d3.tar.bz2 dokka-9e8455d8a5285bfbdd92cab1515270f695a9b5d3.zip |
Make Location provider use anchor hints
Diffstat (limited to 'plugins/base')
5 files changed, 28 insertions, 4 deletions
diff --git a/plugins/base/src/main/kotlin/resolvers/anchors/AnchorsHint.kt b/plugins/base/src/main/kotlin/resolvers/anchors/AnchorsHint.kt new file mode 100644 index 00000000..1b741484 --- /dev/null +++ b/plugins/base/src/main/kotlin/resolvers/anchors/AnchorsHint.kt @@ -0,0 +1,9 @@ +package org.jetbrains.dokka.base.resolvers.anchors + +import org.jetbrains.dokka.model.properties.ExtraProperty +import org.jetbrains.dokka.pages.ContentNode + +// TODO IMPORTANT: https://github.com/Kotlin/dokka/issues/1054 +object SymbolAnchorHint: ExtraProperty<ContentNode>, ExtraProperty.Key<ContentNode, SymbolAnchorHint> { + override val key = this +}
\ No newline at end of file diff --git a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt index ba4523a1..1df0a700 100644 --- a/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt +++ b/plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt @@ -2,6 +2,7 @@ package org.jetbrains.dokka.base.resolvers.local import org.jetbrains.dokka.DokkaConfiguration import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet +import org.jetbrains.dokka.base.resolvers.anchors.SymbolAnchorHint import org.jetbrains.dokka.base.resolvers.external.ExternalLocationProvider import org.jetbrains.dokka.links.DRI import org.jetbrains.dokka.model.withDescendants @@ -27,6 +28,16 @@ open class DefaultLocationProvider( if (first) page else throw AssertionError("Multiple pages associated with dri: $dri") } + protected val anchorsIndex = pageGraphRoot.withDescendants().filterIsInstance<ContentPage>() + .flatMap { page -> + page.content.withDescendants() + .filter { it.extra[SymbolAnchorHint] != null } + .mapNotNull { it.dci.dri.singleOrNull() } + .distinct() + .map { it to page } + }.toMap() + + protected val pathsIndex: Map<PageNode, List<String>> = IdentityHashMap<PageNode, List<String>>().apply { fun registerPath(page: PageNode, prefix: List<String>) { val newPrefix = prefix + page.pathName @@ -41,9 +52,10 @@ open class DefaultLocationProvider( pathTo(node, context) + if (!skipExtension) extension else "" override fun resolve(dri: DRI, sourceSets: Set<DokkaSourceSet>, context: PageNode?): String = - pagesIndex[dri]?.let { resolve(it, context) } ?: + pagesIndex[dri]?.let { resolve(it, context) } + ?: anchorsIndex[dri]?.let { resolve(it, context) + "#$dri" } // Not found in PageGraph, that means it's an external link - getExternalLocation(dri, sourceSets) + ?: getExternalLocation(dri, sourceSets) override fun resolveRoot(node: PageNode): String = pathTo(pageGraphRoot, node).removeSuffix(PAGE_WITH_CHILDREN_SUFFIX) diff --git a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt index eb2989db..19df2515 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/DefaultPageCreator.kt @@ -132,6 +132,7 @@ open class DefaultPageCreator( ContentKind.Properties, s.properties, sourceSets.toSet(), + needsAnchors = true, extra = mainExtra + SimpleAttr.header("Properties") ) { link(it.name, it.dri, kind = ContentKind.Main) diff --git a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt index babcc1c7..58b384e2 100644 --- a/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt +++ b/plugins/base/src/main/kotlin/translators/documentables/PageContentBuilder.kt @@ -1,6 +1,7 @@ package org.jetbrains.dokka.base.translators.documentables import org.jetbrains.dokka.DokkaConfiguration.DokkaSourceSet +import org.jetbrains.dokka.base.resolvers.anchors.SymbolAnchorHint import org.jetbrains.dokka.base.signatures.SignatureProvider import org.jetbrains.dokka.base.transformers.pages.comments.CommentsToContentConverter import org.jetbrains.dokka.links.DRI @@ -167,6 +168,7 @@ open class PageContentBuilder( renderWhenEmpty: Boolean = false, needsSorting: Boolean = true, headers: List<ContentGroup>? = null, + needsAnchors: Boolean = false, operation: DocumentableContentBuilder.(T) -> Unit ) { if (renderWhenEmpty || elements.any()) { @@ -180,7 +182,8 @@ open class PageContentBuilder( else it } .map { - buildGroup(setOf(it.dri), it.sourceSets.toSet(), kind, styles, extra) { + val newExtra = if (needsAnchors) extra + SymbolAnchorHint else extra + buildGroup(setOf(it.dri), it.sourceSets.toSet(), kind, styles, newExtra) { operation(it) } }, diff --git a/plugins/base/src/test/kotlin/utils/TestOutputWriter.kt b/plugins/base/src/test/kotlin/utils/TestOutputWriter.kt index 83f1d180..00b865b4 100644 --- a/plugins/base/src/test/kotlin/utils/TestOutputWriter.kt +++ b/plugins/base/src/test/kotlin/utils/TestOutputWriter.kt @@ -20,7 +20,6 @@ class TestOutputWriter(private val failOnOverwrite: Boolean = true) : OutputWrit val contents: Map<String, String> get() = _contents private val _contents = mutableMapOf<String, String>() - override suspend fun write(path: String, text: String, ext: String) { val fullPath = "$path$ext" _contents.putIfAbsent(fullPath, text)?.also { |