Skip to content

Commit f1035f5

Browse files
authored
Merge pull request #54 from sourcegraph/nsc/empty-kdoc-fix
fix outofbounds exception when kdoc line is empty
2 parents 51b3e0d + 4d77f55 commit f1035f5

File tree

3 files changed

+43
-1
lines changed

3 files changed

+43
-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@forEach
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: 42 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,44 @@ 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+
|
605+
|hello world
606+
|* test content
607+
|*/
608+
|val x = ""
609+
|""".trimMargin()),
610+
semanticdb = SemanticdbData(
611+
expectedSymbols =
612+
listOf(
613+
SymbolInformation {
614+
symbol = "TestKt#x."
615+
displayName = "x"
616+
language = Language.KOTLIN
617+
documentation {
618+
message = "```kt\npublic val x: kotlin.String\n```\n\n----\n\n\nhello world\n test content\n"
619+
format = Format.MARKDOWN
620+
}
621+
},
622+
SymbolInformation {
623+
symbol = "TestKt#getX()."
624+
displayName = "x"
625+
language = Language.KOTLIN
626+
documentation {
627+
message = "```kt\npublic val x: kotlin.String\n```\n\n----\n\n\nhello world\n test content\n"
628+
format = Format.MARKDOWN
629+
}
630+
}
631+
)
632+
)
633+
)
634+
).mapCheckExpectedSymbols()
593635
}

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)