diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2019-03-18 21:56:14 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2019-03-18 21:56:14 +0300 |
commit | 4b22ebab09ce3b934443d063df6b905e5347c390 (patch) | |
tree | f353662dc777107773adf8a5b3cac07b09ab3255 /core/src/main/kotlin/Model/SourceLinks.kt | |
parent | 0fa9b69b6afe762e5aee7b7cf801a38ebe74b2c9 (diff) | |
parent | b566f8852e94f9a17be86bf845aeff6c36bd8378 (diff) | |
download | dokka-4b22ebab09ce3b934443d063df6b905e5347c390.tar.gz dokka-4b22ebab09ce3b934443d063df6b905e5347c390.tar.bz2 dokka-4b22ebab09ce3b934443d063df6b905e5347c390.zip |
Merge branch 'dev-pre' into dev
# Conflicts:
# core/src/main/kotlin/Model/PackageDocs.kt
Diffstat (limited to 'core/src/main/kotlin/Model/SourceLinks.kt')
-rw-r--r-- | core/src/main/kotlin/Model/SourceLinks.kt | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/core/src/main/kotlin/Model/SourceLinks.kt b/core/src/main/kotlin/Model/SourceLinks.kt index 2c75cfda..99ee362e 100644 --- a/core/src/main/kotlin/Model/SourceLinks.kt +++ b/core/src/main/kotlin/Model/SourceLinks.kt @@ -10,20 +10,20 @@ import java.io.File fun DocumentationNode.appendSourceLink(psi: PsiElement?, sourceLinks: List<SourceLinkDefinition>) { val path = psi?.containingFile?.virtualFile?.path ?: return + val canonicalPath = File(path).canonicalPath val target = if (psi is PsiNameIdentifierOwner) psi.nameIdentifier else psi - val absPath = File(path).absolutePath - val linkDef = sourceLinks.firstOrNull { absPath.startsWith(it.path) } - if (linkDef != null) { - var url = linkDef.url + path.substring(linkDef.path.length) - if (linkDef.lineSuffix != null) { + val pair = determineSourceLinkDefinition(canonicalPath, sourceLinks) + if (pair != null) { + val (sourceLinkDefinition, sourceLinkCanonicalPath) = pair + var url = determineUrl(canonicalPath, sourceLinkDefinition, sourceLinkCanonicalPath) + if (sourceLinkDefinition.lineSuffix != null) { val line = target?.lineNumber() if (line != null) { - url += linkDef.lineSuffix + line.toString() + url += sourceLinkDefinition.lineSuffix + line.toString() } } - append(DocumentationNode(url, Content.Empty, NodeKind.SourceUrl), - RefKind.Detail); + append(DocumentationNode(url, Content.Empty, NodeKind.SourceUrl), RefKind.Detail) } if (target != null) { @@ -31,6 +31,28 @@ fun DocumentationNode.appendSourceLink(psi: PsiElement?, sourceLinks: List<Sourc } } +private fun determineSourceLinkDefinition( + canonicalPath: String, + sourceLinks: List<SourceLinkDefinition> +): Pair<SourceLinkDefinition, String>? { + return sourceLinks + .asSequence() + .map { it to File(it.path).canonicalPath } + .firstOrNull { (_, sourceLinkCanonicalPath) -> + canonicalPath.startsWith(sourceLinkCanonicalPath) + } +} + +private fun determineUrl( + canonicalPath: String, + sourceLinkDefinition: SourceLinkDefinition, + sourceLinkCanonicalPath: String +): String { + val relativePath = canonicalPath.substring(sourceLinkCanonicalPath.length) + val relativeUrl = relativePath.replace('\\', '/').removePrefix("/") + return "${sourceLinkDefinition.url.removeSuffix("/")}/$relativeUrl" +} + private fun PsiElement.sourcePosition(): String { val path = containingFile.virtualFile.path val lineNumber = lineNumber() |