diff options
author | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2019-03-18 22:05:22 +0300 |
---|---|---|
committer | Simon Ogorodnik <Simon.Ogorodnik@jetbrains.com> | 2019-03-18 22:05:22 +0300 |
commit | fd2f36301e95f8d100e1c2b942f1590144d8c6c2 (patch) | |
tree | dcbf109f14de5301848c29e9721c8e0af6881b3e /core/src/main/kotlin/Model/SourceLinks.kt | |
parent | f2359e05347708e625d5a6b339010cda2adc30de (diff) | |
parent | 4b22ebab09ce3b934443d063df6b905e5347c390 (diff) | |
download | dokka-fd2f36301e95f8d100e1c2b942f1590144d8c6c2.tar.gz dokka-fd2f36301e95f8d100e1c2b942f1590144d8c6c2.tar.bz2 dokka-fd2f36301e95f8d100e1c2b942f1590144d8c6c2.zip |
Merge branch 'dev'
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() |