Skip to content

Commit

Permalink
Merge pull request #54 from sourcegraph/nsc/empty-kdoc-fix
Browse files Browse the repository at this point in the history
fix outofbounds exception when kdoc line is empty
  • Loading branch information
Strum355 authored Apr 17, 2023
2 parents 51b3e0d + 4d77f55 commit f1035f5
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ class SemanticdbTextDocumentBuilder(
if (kdoc.isEmpty()) return kdoc
val out = StringBuilder().append("\n\n").append("----").append("\n")
kdoc.lineSequence().forEach { line ->
if (line.isEmpty()) return@forEach
var start = 0
while (start < line.length && line[start].isWhitespace()) {
start++
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.sourcegraph.semanticdb_kotlinc.test

import com.sourcegraph.semanticdb_kotlinc.*
import com.sourcegraph.semanticdb_kotlinc.Semanticdb.Documentation.Format
import com.sourcegraph.semanticdb_kotlinc.Semanticdb.Language
import com.sourcegraph.semanticdb_kotlinc.Semanticdb.SymbolOccurrence.Role
import com.sourcegraph.semanticdb_kotlinc.test.ExpectedSymbols.SemanticdbData
import com.sourcegraph.semanticdb_kotlinc.test.ExpectedSymbols.SymbolCacheData
Expand Down Expand Up @@ -590,4 +592,44 @@ class SemanticdbSymbolsTest {
}
}))))
.mapCheckExpectedSymbols()

@TestFactory
fun kdoc() =
listOf(
ExpectedSymbols(
"empty kdoc line",
SourceFile.testKt(
"""
|/**
|
|hello world
|* test content
|*/
|val x = ""
|""".trimMargin()),
semanticdb = SemanticdbData(
expectedSymbols =
listOf(
SymbolInformation {
symbol = "TestKt#x."
displayName = "x"
language = Language.KOTLIN
documentation {
message = "```kt\npublic val x: kotlin.String\n```\n\n----\n\n\nhello world\n test content\n"
format = Format.MARKDOWN
}
},
SymbolInformation {
symbol = "TestKt#getX()."
displayName = "x"
language = Language.KOTLIN
documentation {
message = "```kt\npublic val x: kotlin.String\n```\n\n----\n\n\nhello world\n test content\n"
format = Format.MARKDOWN
}
}
)
)
)
).mapCheckExpectedSymbols()
}
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

rootProject.name = "lsif-kotlin"

include(
Expand Down

0 comments on commit f1035f5

Please sign in to comment.