From 712bb8ba9b146c769b84503e332fc449ff942141 Mon Sep 17 00:00:00 2001 From: Simon Ogorodnik Date: Thu, 4 Oct 2018 06:44:17 +0300 Subject: Take GroupNodes into account when computing node location --- core/src/main/kotlin/Locations/Location.kt | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'core/src/main/kotlin/Locations') 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, hasMembers: Boolean): String } } +fun nodeActualQualifier(node: DocumentationNode): List { + 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--" -- cgit