Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: occasional crash when opening kotlin files (#872)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsaky committed Mar 23, 2023
1 parent 1b55e8d commit 8f5284a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Binary file modified app/src/main/assets/data/common/tooling-api-all.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,13 @@ abstract class TreeSitterLanguage(context: Context, lang: TSLanguage, type: Stri
column: Int,
decrementBy: Int = 0
): Int {
val indentsQuery = languageSpec.indentsQuery ?: return 0
return TSParser().use { parser ->
parser.language = languageSpec.language
val tree = parser.parseString(content)

return@use TSQueryCursor().use { cursor ->
cursor.exec(languageSpec.indentsQuery, tree.rootNode)
cursor.exec(indentsQuery, tree.rootNode)

var indent = 0
var match: TSQueryMatch? = cursor.nextMatch()
Expand All @@ -133,7 +134,7 @@ abstract class TreeSitterLanguage(context: Context, lang: TSLanguage, type: Stri
break
}

val captureName = languageSpec.indentsQuery.getCaptureNameForId(capture.index)
val captureName = indentsQuery.getCaptureNameForId(capture.index)
if (captureName == "indent") {
++indent
} else if (captureName == "outdent") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,17 @@ constructor(val spec: TsLanguageSpec, indentsQueryScm: String = "") : Closeable
get() = spec.language
// </editor-fold>

val indentsQuery = TSQuery(language, indentsQueryScm)
val indentsQuery: TSQuery? =
if (indentsQueryScm.isBlank()) {
TSQuery(language, indentsQueryScm)
} else null

init {
indentsQuery.validateOrThrow(name = "indents")
indentsQuery?.validateOrThrow(name = "indents")
}

override fun close() {
indentsQuery.close()
indentsQuery?.close()
spec.close()
}
}
Expand Down

0 comments on commit 8f5284a

Please sign in to comment.