diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Kotlin/DocumentationBuilder.kt | 28 | ||||
-rw-r--r-- | src/Model/SourceLinks.kt | 31 | ||||
-rw-r--r-- | src/main.kt | 2 |
3 files changed, 32 insertions, 29 deletions
diff --git a/src/Kotlin/DocumentationBuilder.kt b/src/Kotlin/DocumentationBuilder.kt index 068f251a..04b707af 100644 --- a/src/Kotlin/DocumentationBuilder.kt +++ b/src/Kotlin/DocumentationBuilder.kt @@ -191,35 +191,9 @@ class DocumentationBuilder(val session: ResolveSession, val options: Documentati } fun DocumentationNode.appendSourceLink(sourceElement: SourceElement) { - val psi = getTargetElement(sourceElement) - val path = psi?.getContainingFile()?.getVirtualFile()?.getPath() - if (path == null) { - return - } - val absPath = File(path).getAbsolutePath() - val linkDef = findSourceLinkDefinition(absPath) - if (linkDef != null) { - var url = linkDef.url + path.substring(linkDef.path.length()) - if (linkDef.lineSuffix != null) { - val doc = PsiDocumentManager.getInstance(psi!!.getProject()).getDocument(psi.getContainingFile()) - if (doc != null) { - // IJ uses 0-based line-numbers; external source browsers use 1-based - val line = doc.getLineNumber(psi.getTextRange().getStartOffset()) + 1 - url += linkDef.lineSuffix + line.toString() - } - } - append(DocumentationNode(url, Content.Empty, DocumentationNode.Kind.SourceUrl), - DocumentationReference.Kind.Detail); - } - } - - private fun getTargetElement(sourceElement: SourceElement): PsiElement? { - val psi = sourceElement.getPsi() - return if (psi is PsiNameIdentifierOwner) psi.getNameIdentifier() else psi + appendSourceLink(sourceElement.getPsi(), options.sourceLinks) } - fun findSourceLinkDefinition(path: String) = options.sourceLinks.firstOrNull { path.startsWith(it.path) } - fun DocumentationNode.appendChild(descriptor: DeclarationDescriptor, kind: DocumentationReference.Kind) { // do not include generated code if (descriptor is CallableMemberDescriptor && descriptor.getKind() != CallableMemberDescriptor.Kind.DECLARATION) diff --git a/src/Model/SourceLinks.kt b/src/Model/SourceLinks.kt new file mode 100644 index 00000000..556b813b --- /dev/null +++ b/src/Model/SourceLinks.kt @@ -0,0 +1,31 @@ +package org.jetbrains.dokka + +import com.intellij.psi.PsiElement +import java.io.File +import com.intellij.psi.PsiDocumentManager +import com.intellij.psi.PsiNameIdentifierOwner + +class SourceLinkDefinition(val path: String, val url: String, val lineSuffix: String?) + +fun DocumentationNode.appendSourceLink(psi: PsiElement?, sourceLinks: List<SourceLinkDefinition>) { + val path = psi?.getContainingFile()?.getVirtualFile()?.getPath() + if (path == null) { + return + } + val target = if (psi is PsiNameIdentifierOwner) psi.getNameIdentifier() else psi + val absPath = File(path).getAbsolutePath() + 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 doc = PsiDocumentManager.getInstance(psi!!.getProject()).getDocument(psi.getContainingFile()) + if (doc != null) { + // IJ uses 0-based line-numbers; external source browsers use 1-based + val line = doc.getLineNumber(target!!.getTextRange().getStartOffset()) + 1 + url += linkDef.lineSuffix + line.toString() + } + } + append(DocumentationNode(url, Content.Empty, DocumentationNode.Kind.SourceUrl), + DocumentationReference.Kind.Detail); + } +} diff --git a/src/main.kt b/src/main.kt index d5384ea0..c422b9f6 100644 --- a/src/main.kt +++ b/src/main.kt @@ -48,8 +48,6 @@ class DokkaArguments { } -class SourceLinkDefinition(val path: String, val url: String, val lineSuffix: String?) - private fun parseSourceLinkDefinition(srcLink: String): SourceLinkDefinition { val (path, urlAndLine) = srcLink.split('=') return SourceLinkDefinition(File(path).getAbsolutePath(), |