Skip to content

Commit

Permalink
Improve tsq/tree-sitter-query language support (#12148)
Browse files Browse the repository at this point in the history
  • Loading branch information
uncenter authored Dec 27, 2024
1 parent 7b9b932 commit a5a7cff
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 42 deletions.
2 changes: 1 addition & 1 deletion book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
| thrift || | | |
| todotxt || | | |
| toml ||| | `taplo` |
| tsq || | | |
| tsq || | | `ts_query_ls` |
| tsx |||| `typescript-language-server` |
| twig || | | |
| typescript |||| `typescript-language-server` |
Expand Down
14 changes: 11 additions & 3 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions runtime/queries/tsq/folds.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
(named_node)
(predicate)
(grouping)
(list)
] @fold
73 changes: 40 additions & 33 deletions runtime/queries/tsq/highlights.scm
Original file line number Diff line number Diff line change
@@ -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
12 changes: 7 additions & 5 deletions runtime/queries/tsq/injections.scm
Original file line number Diff line number Diff line change
@@ -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"))

0 comments on commit a5a7cff

Please sign in to comment.