Unnamed repository; edit this file 'description' to name the repository.
Improve tsq/tree-sitter-query language support (#12148)
uncenter 2024-12-27
parent 7b9b932 · commit a5a7cff
-rw-r--r--book/src/generated/lang-support.md2
-rw-r--r--languages.toml14
-rw-r--r--runtime/queries/tsq/folds.scm6
-rw-r--r--runtime/queries/tsq/highlights.scm73
-rw-r--r--runtime/queries/tsq/injections.scm12
5 files changed, 65 insertions, 42 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index 850facd1..7c529e99 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -217,7 +217,7 @@
| thrift | ✓ | | | |
| todotxt | ✓ | | | |
| toml | ✓ | ✓ | | `taplo` |
-| tsq | ✓ | | | |
+| tsq | ✓ | | | `ts_query_ls` |
| tsx | ✓ | ✓ | ✓ | `typescript-language-server` |
| twig | ✓ | | | |
| typescript | ✓ | ✓ | ✓ | `typescript-language-server` |
diff --git a/languages.toml b/languages.toml
index 661982f4..f415fb61 100644
--- a/languages.toml
+++ b/languages.toml
@@ -122,6 +122,7 @@ zls = { command = "zls" }
blueprint-compiler = { command = "blueprint-compiler", args = ["lsp"] }
typst-lsp = { command = "typst-lsp" }
tinymist = { command = "tinymist" }
+ts_query_ls = { command = "ts_query_ls" }
pkgbuild-language-server = { command = "pkgbuild-language-server" }
helm_ls = { command = "helm_ls", args = ["serve"] }
ember-language-server = { command = "ember-language-server", args = ["--stdio"] }
@@ -1458,14 +1459,21 @@ language-servers = [ "swipl" ]
[[language]]
name = "tsq"
scope = "source.tsq"
-file-types = ["tsq"]
+file-types = [{ glob = "queries/*.scm" }, { glob = "injections.scm" }, { glob = "highlights.scm" }, { glob = "indents.scm" }, { glob = "textobjects.scm" }, { glob = "locals.scm" }, { glob = "tags.scm" }]
comment-token = ";"
injection-regex = "tsq"
+language-servers = ["ts_query_ls"]
+grammar = "query"
indent = { tab-width = 2, unit = " " }
+[language.auto-pairs]
+'(' = ')'
+'[' = ']'
+'"' = '"'
+
[[grammar]]
-name = "tsq"
-source = { git = "https://github.com/the-mikedavis/tree-sitter-tsq", rev = "48b5e9f82ae0a4727201626f33a17f69f8e0ff86" }
+name = "query"
+source = { git = "https://github.com/tree-sitter-grammars/tree-sitter-query", rev = "a6674e279b14958625d7a530cabe06119c7a1532" }
[[language]]
name = "cmake"
diff --git a/runtime/queries/tsq/folds.scm b/runtime/queries/tsq/folds.scm
new file mode 100644
index 00000000..47dd9651
--- /dev/null
+++ b/runtime/queries/tsq/folds.scm
@@ -0,0 +1,6 @@
+[
+ (named_node)
+ (predicate)
+ (grouping)
+ (list)
+] @fold
diff --git a/runtime/queries/tsq/highlights.scm b/runtime/queries/tsq/highlights.scm
index 5ef6bf4c..67d22744 100644
--- a/runtime/queries/tsq/highlights.scm
+++ b/runtime/queries/tsq/highlights.scm
@@ -1,50 +1,57 @@
-; mark the string passed #match? as a regex
-(((predicate_name) @function
- (capture)
- (string) @string.regexp)
- (#eq? @function "#match?"))
+((program
+ .
+ (comment)*
+ .
+ (comment) @keyword.import)
+ (#match? @keyword.import "^;+ *inherits *:"))
-; highlight inheritance comments
-(((comment) @keyword.directive)
- (#match? @keyword.directive "^; +inherits *:"))
+((parameters
+ (identifier) @constant.numeric)
+ (#match? @constant.numeric "^[-+]?[0-9]+(.[0-9]+)?$"))
+
+"_" @constant
[
- "("
- ")"
- "["
- "]"
-] @punctuation.bracket
+ "@"
+ "#"
+] @punctuation.special
":" @punctuation.delimiter
-"!" @operator
[
- (one_or_more)
- (zero_or_one)
- (zero_or_more)
-] @operator
+ "["
+ "]"
+ "("
+ ")"
+] @punctuation.bracket
-[
- (wildcard_node)
- (anchor)
-] @constant.builtin
+"." @operator
-[
- (anonymous_leaf)
- (string)
-] @string
+(predicate_type) @punctuation.special
+
+(quantifier) @operator
(comment) @comment
-(field_name) @variable.other.member
+(negated_field
+ "!" @operator
+ (identifier) @variable.other.member)
+
+(field_definition
+ name: (identifier) @variable.other.member)
+
+(named_node
+ name: (identifier) @variable)
+
+(predicate
+ name: (identifier) @function)
-(capture) @label
+(anonymous_node
+ (string) @string)
-((predicate_name) @function
- (#any-of? @function "#eq?" "#match?" "#any-of?" "#not-any-of?" "#is?" "#is-not?" "#not-same-line?" "#not-kind-eq?" "#set!" "#select-adjacent!" "#strip!"))
-(predicate_name) @error
+(capture
+ (identifier) @type)
(escape_sequence) @constant.character.escape
-(node_name) @tag
-(variable) @variable
+(string) @string
diff --git a/runtime/queries/tsq/injections.scm b/runtime/queries/tsq/injections.scm
index 64404557..253a9bdb 100644
--- a/runtime/queries/tsq/injections.scm
+++ b/runtime/queries/tsq/injections.scm
@@ -1,8 +1,10 @@
((comment) @injection.content
- (#set! injection.language "comment"))
+ (#set! injection.language "comment"))
((predicate
- (predicate_name) @_predicate
- (string) @injection.content)
- (#eq? @_predicate "#match?")
- (#set! injection.language "regex"))
+ name: (identifier) @_name
+ parameters:
+ (parameters
+ (string) @injection.content))
+ (#any-of? @_name "match" "not-match")
+ (#set! injection.language "regex"))