Skip to content

Commit e992475

Browse files
committed
fix outofbounds exception when kdoc line is empty
1 parent 51b3e0d commit e992475

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

semanticdb-kotlinc/src/main/kotlin/com/sourcegraph/semanticdb_kotlinc/SemanticdbTextDocumentBuilder.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ class SemanticdbTextDocumentBuilder(
133133
if (kdoc.isEmpty()) return kdoc
134134
val out = StringBuilder().append("\n\n").append("----").append("\n")
135135
kdoc.lineSequence().forEach { line ->
136+
if (line.isEmpty()) return ""
136137
var start = 0
137138
while (start < line.length && line[start].isWhitespace()) {
138139
start++

semanticdb-kotlinc/src/test/kotlin/com/sourcegraph/semanticdb_kotlinc/test/SemanticdbSymbolsTest.kt

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.sourcegraph.semanticdb_kotlinc.test
22

33
import com.sourcegraph.semanticdb_kotlinc.*
4+
import com.sourcegraph.semanticdb_kotlinc.Semanticdb.Documentation.Format
5+
import com.sourcegraph.semanticdb_kotlinc.Semanticdb.Language
46
import com.sourcegraph.semanticdb_kotlinc.Semanticdb.SymbolOccurrence.Role
57
import com.sourcegraph.semanticdb_kotlinc.test.ExpectedSymbols.SemanticdbData
68
import com.sourcegraph.semanticdb_kotlinc.test.ExpectedSymbols.SymbolCacheData
@@ -590,4 +592,43 @@ class SemanticdbSymbolsTest {
590592
}
591593
}))))
592594
.mapCheckExpectedSymbols()
595+
596+
@TestFactory
597+
fun kdoc() =
598+
listOf(
599+
ExpectedSymbols(
600+
"empty kdoc line",
601+
SourceFile.testKt(
602+
"""
603+
|/**
604+
|hello world
605+
|* test content
606+
|*/
607+
|val x = ""
608+
|""".trimMargin()),
609+
semanticdb = SemanticdbData(
610+
expectedSymbols =
611+
listOf(
612+
SymbolInformation {
613+
symbol = "TestKt#x."
614+
displayName = "x"
615+
language = Language.KOTLIN
616+
documentation {
617+
message = "```kt\npublic val x: kotlin.String\n```\n\n----\n\n\nhello world\n test content\n"
618+
format = Format.MARKDOWN
619+
}
620+
},
621+
SymbolInformation {
622+
symbol = "TestKt#getX()."
623+
displayName = "x"
624+
language = Language.KOTLIN
625+
documentation {
626+
message = "```kt\npublic val x: kotlin.String\n```\n\n----\n\n\nhello world\n test content\n"
627+
format = Format.MARKDOWN
628+
}
629+
}
630+
)
631+
)
632+
)
633+
).mapCheckExpectedSymbols()
593634
}

settings.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
rootProject.name = "lsif-kotlin"
32

43
include(

0 commit comments

Comments
 (0)