Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: migrate to android-tree-sitter v3.0.0 #439

Merged
merged 1 commit into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
agp = "8.0.1"
kotlin = "1.8.20"
lifecycle = "2.5.1"
tsBinding = "2.0.0"
tsBinding = "3.0.0"
lsp4j = "0.20.1"
androidxAnnotation = "1.6.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ open class TsAnalyzeManager(val languageSpec: TsLanguageSpec, var theme: TsTheme
}

fun updateCodeBlocks() {
if (languageSpec.blocksQuery.patternCount == 0) {
if (languageSpec.blocksQuery.patternCount == 0 || !languageSpec.blocksQuery.isValid) {
return
}
val blocks = mutableListOf<CodeBlock>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class TsBracketPairs(
}

override fun getPairedBracketAt(text: Content, index: Int): PairedBracket? {
if (languageSpec.bracketsQuery.patternCount > 0) {
if (languageSpec.bracketsQuery.patternCount > 0 && languageSpec.bracketsQuery.isValid) {
TSQueryCursor().use { cursor ->
cursor.setByteRange(max(0, index - 1) * 2, index * 2 + 1)
cursor.exec(languageSpec.bracketsQuery, tree.rootNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ open class TsLanguageSpec(
/**
* The actual [TSQuery] object
*/
val tsQuery = TSQuery(language, querySource)
val tsQuery = TSQuery.create(language, querySource)

/**
* The first index of highlighting pattern
Expand Down Expand Up @@ -107,9 +107,9 @@ open class TsLanguageSpec(
*/
val localsDefinitionValueIndices = mutableListOf<Int>()

val blocksQuery = TSQuery(language, codeBlocksScmSource)
val blocksQuery = TSQuery.create(language, codeBlocksScmSource)

val bracketsQuery = TSQuery(language, bracketsScmSource)
val bracketsQuery = TSQuery.create(language, bracketsScmSource)

init {
// Check the queries before access
Expand All @@ -121,6 +121,9 @@ open class TsLanguageSpec(
throw IllegalArgumentException("use non-ASCII characters in scm source is unexpected")
}
}
if (!tsQuery.isValid) {
throw IllegalArgumentException("Syntax highlights query is invalid")
}
if (tsQuery.errorType != TSQueryError.None) {
val region = if (tsQuery.errorOffset < highlightScmOffset) "locals" else "highlight"
val offset =
Expand Down