aboutsummaryrefslogtreecommitdiff
path: root/plugins/base/src/main/kotlin/resolvers
diff options
context:
space:
mode:
authorPaweł Marks <pmarks@virtuslab.com>2020-07-06 10:08:43 +0200
committerPaweł Marks <Kordyjan@users.noreply.github.com>2020-07-07 13:23:26 +0200
commit9e8455d8a5285bfbdd92cab1515270f695a9b5d3 (patch)
treeccd79e5b5cdb533dbb62e8de63930b5a6adbb851 /plugins/base/src/main/kotlin/resolvers
parent2da1f3b1612fd19be8082283c6d070759a42de12 (diff)
downloaddokka-9e8455d8a5285bfbdd92cab1515270f695a9b5d3.tar.gz
dokka-9e8455d8a5285bfbdd92cab1515270f695a9b5d3.tar.bz2
dokka-9e8455d8a5285bfbdd92cab1515270f695a9b5d3.zip
Make Location provider use anchor hints
Diffstat (limited to 'plugins/base/src/main/kotlin/resolvers')
-rw-r--r--plugins/base/src/main/kotlin/resolvers/anchors/AnchorsHint.kt9
-rw-r--r--plugins/base/src/main/kotlin/resolvers/local/DefaultLocationProvider.kt16
2 files changed, 23 insertions, 2 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)