aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/src/main/kotlin/Formats/StructuredFormatService.kt75
-rw-r--r--core/src/main/kotlin/Locations/Location.kt18
2 files changed, 64 insertions, 29 deletions
diff --git a/core/src/main/kotlin/Formats/StructuredFormatService.kt b/core/src/main/kotlin/Formats/StructuredFormatService.kt
index f989fad6..33d26a93 100644
--- a/core/src/main/kotlin/Formats/StructuredFormatService.kt
+++ b/core/src/main/kotlin/Formats/StructuredFormatService.kt
@@ -55,8 +55,6 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
val extension: String,
impliedPlatforms: List<String>) : FormattedOutputBuilder {
- protected fun DocumentationNode.location() = generator.location(this)
-
protected fun wrap(prefix: String, suffix: String, body: () -> Unit) {
to.append(prefix)
body()
@@ -209,7 +207,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
is ContentNodeLink -> {
val node = content.node
- val linkTo = if (node != null) locationHref(location, node) else "#"
+ val linkTo = if (node != null) locationHref(location, node, generator) else "#"
appendLinkIfNotThisPage(linkTo, content)
}
is ContentExternalLink -> appendLinkIfNotThisPage(content.href, content)
@@ -259,17 +257,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
extension: String,
name: (DocumentationNode) -> String = DocumentationNode::name
): FormatLink =
- FormatLink(name(to), from.location().relativePathTo(to.location()))
-
-
- fun locationHref(from: Location, to: DocumentationNode): String {
- val topLevelPage = to.references(RefKind.TopLevelPage).singleOrNull()?.to
- if (topLevelPage != null) {
- val signature = to.detailOrNull(NodeKind.Signature)
- return from.relativePathTo(topLevelPage.location(), signature?.name ?: to.name)
- }
- return from.relativePathTo(to.location())
- }
+ FormatLink(name(to), generator.relativePathToLocation(from, to))
private fun DocumentationNode.isModuleOrPackage(): Boolean =
kind == NodeKind.Module || kind == NodeKind.Package
@@ -467,6 +455,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
for ((sign, nodes) in groupBySignature) {
appendAsPlatformDependentBlock(effectivePlatformsForMembers(nodes)) { platforms ->
+ println("GNPM: ${platforms.toList().joinToString { "${it.first}->${it.second.map { it.path.joinToString(separator = ">") }}" }}")
val first = nodes.first()
first.detailOrNull(NodeKind.Signature)?.let {
if (item.kind !in NodeKind.classLike || !isSingleNode)
@@ -499,7 +488,7 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
overrides.forEach {
appendParagraph {
to.append("Overrides ")
- val location = location().relativePathTo(it.location())
+ val location = generator.relativePathToLocation(this, it)
appendLink(FormatLink(it.owner!!.name + "." + it.name, location))
}
@@ -533,8 +522,6 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
-
-
// protected fun platformsOfItems(items: List<DocumentationNode>): Set<String> {
// val platforms = items.asSequence().map {
// when (it.kind) {
@@ -620,6 +607,29 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
}
}
}
+
+ fun appendOriginsGroupByContent(node: DocumentationNode) {
+ require(node.kind == NodeKind.GroupNode)
+ val groupByContent =
+ node.origins.groupBy { it.content }
+ .mapValues { (_, origins) ->
+ effectivePlatformsForMembers(origins)
+ }
+ .filterNot { it.key.isEmpty() }
+ .toList()
+ .sortedByDescending { it.second.size }
+
+
+ for ((content, platforms) in groupByContent) {
+ appendAsPlatformDependentBlock(platforms) {
+ if (groupByContent.size > 1) {
+ appendPlatformsAsText(platforms)
+ }
+ appendContent(content.summary)
+ content.appendDescription()
+ }
+ }
+ }
}
inner class SingleNodePageBuilder(val node: DocumentationNode, noHeader: Boolean = false) :
@@ -644,18 +654,10 @@ abstract class StructuredOutputBuilder(val to: StringBuilder,
appendAsNodeDescription(effectivePlatformsForNode(node)) {
renderGroupNode(node, true)
- val groupByContent = node.origins.groupBy { it.content }
- for ((content, origins) in groupByContent) {
- if (content.isEmpty()) continue
- appendAsPlatformDependentBlock(effectivePlatformsForMembers(origins)) { platforms ->
- if (groupByContent.keys.count { !it.isEmpty() } > 1) {
- appendPlatformsAsText(platforms)
- }
- appendContent(content)
- }
- }
+ appendOriginsGroupByContent(node)
}
+ println("GN: ${node.path}")
SectionsBuilder(node).build()
}
}
@@ -925,6 +927,8 @@ typealias PlatformsData = Map<String, Set<DocumentationNode>>
fun memberPlatforms(node: DocumentationNode): PlatformsData {
val members = when {
node.kind == NodeKind.GroupNode -> node.origins
+ node.kind in NodeKind.classLike -> emptyList()
+ node.kind in NodeKind.memberLike -> emptyList()
else -> node.members
}
@@ -974,4 +978,21 @@ fun samePlatforms(platformsPerNode: Collection<PlatformsData>): Boolean {
val first = platformsPerNode.firstOrNull()?.keys ?: return true
return platformsPerNode.all { it.keys == first }
+}
+
+fun locationHref(
+ from: Location,
+ to: DocumentationNode,
+ generator: NodeLocationAwareGenerator,
+ pathOnly: Boolean = false
+): String {
+ val topLevelPage = to.references(RefKind.TopLevelPage).singleOrNull()?.to
+ if (topLevelPage != null) {
+ val signature = to.detailOrNull(NodeKind.Signature)
+ return from.relativePathTo(
+ generator.location(topLevelPage),
+ (signature?.name ?: to.name).takeUnless { pathOnly }
+ )
+ }
+ return from.relativePathTo(generator.location(to))
} \ No newline at end of file
diff --git a/core/src/main/kotlin/Locations/Location.kt b/core/src/main/kotlin/Locations/Location.kt
index 4448fb99..ccefa6e3 100644
--- a/core/src/main/kotlin/Locations/Location.kt
+++ b/core/src/main/kotlin/Locations/Location.kt
@@ -26,7 +26,7 @@ data class FileLocation(val file: File) : Location {
}
val ownerFolder = file.parentFile!!
val relativePath = ownerFolder.toPath().relativize(other.file.toPath()).toString().replace(File.separatorChar, '/')
- return if (anchor == null) relativePath else relativePath + "#" + anchor
+ return if (anchor == null) relativePath else relativePath + "#" + anchor.urlEncoded()
}
}
@@ -40,8 +40,22 @@ fun relativePathToNode(qualifiedName: List<String>, hasMembers: Boolean): String
}
}
+fun nodeActualQualifier(node: DocumentationNode): List<DocumentationNode> {
+ val topLevelPage = node.references(RefKind.TopLevelPage).singleOrNull()?.to
+ if (topLevelPage != null) {
+ return nodeActualQualifier(topLevelPage)
+ }
+ return node.owner?.let { nodeActualQualifier(it) }.orEmpty() + node
+}
+
+fun relativePathToNode(node: DocumentationNode): String {
+ val qualifier = nodeActualQualifier(node)
+ return relativePathToNode(
+ qualifier.map { it.name },
+ qualifier.last().members.any()
+ )
+}
-fun relativePathToNode(node: DocumentationNode) = relativePathToNode(node.path.map { it.name }, node.members.any())
fun identifierToFilename(path: String): String {
if (path.isEmpty()) return "--root--"