Skip to content

Commit

Permalink
Fix source link to the line with name
Browse files Browse the repository at this point in the history
  • Loading branch information
vmishenev committed Oct 19, 2022
1 parent 40da670 commit 68a19ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Expand Up @@ -16,6 +16,7 @@ import org.jetbrains.dokka.plugability.plugin
import org.jetbrains.dokka.plugability.querySingle
import org.jetbrains.dokka.transformers.pages.PageTransformer
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
import org.jetbrains.kotlin.kdoc.psi.api.KDoc
import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.utils.addToStdlib.cast
import java.io.File
Expand Down Expand Up @@ -93,7 +94,7 @@ class SourceLinksTransformer(val context: DokkaContext) : PageTransformer {

private fun PsiElement.lineNumber(): Int? {
// synthetic and some light methods might return null
val textRange = textRange ?: return null
val textRange = this.children.firstOrNull { it !is KDoc }?.textRange ?: return null

val doc = PsiDocumentManager.getInstance(project).getDocument(containingFile)
// IJ uses 0-based line-numbers; external source browsers use 1-based
Expand Down
5 changes: 4 additions & 1 deletion plugins/base/src/test/kotlin/enums/KotlinEnumsTest.kt
Expand Up @@ -398,6 +398,9 @@ class KotlinEnumsTest : BaseAbstractTest() {
|/src/main/kotlin/basic/KotlinEnum.kt
|package testpackage
|
|/**
|* Doc
|*/
|enum class KotlinEnum {
| ONE, TWO, THREE
|}
Expand All @@ -412,7 +415,7 @@ class KotlinEnumsTest : BaseAbstractTest() {
.attr("href")

assertEquals(
"https://github.com/user/repo/tree/master/src/main/kotlin/basic/KotlinEnum.kt#L3",
"https://github.com/user/repo/tree/master/src/main/kotlin/basic/KotlinEnum.kt#L6",
sourceLink
)
}
Expand Down

0 comments on commit 68a19ed

Please sign in to comment.