From b25cdec0377fea9fd0223804ebc2e970ceef5e9c Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Mon, 2 Dec 2024 16:27:04 -0500 Subject: [PATCH 1/5] Update tsq language with new grammar and LSP --- book/src/generated/lang-support.md | 2 +- languages.toml | 14 ++++- runtime/queries/tsq/folds.scm | 6 ++ runtime/queries/tsq/highlights.scm | 94 +++++++++++++++++++----------- runtime/queries/tsq/injections.scm | 12 ++-- 5 files changed, 86 insertions(+), 42 deletions(-) create mode 100644 runtime/queries/tsq/folds.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index f51e9bb1d685..54ecd3da03a9 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -214,7 +214,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 df0a29cf0bd9..576d4f3eb2e2 100644 --- a/languages.toml +++ b/languages.toml @@ -120,6 +120,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"] } @@ -1439,14 +1440,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 000000000000..47dd965126b4 --- /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 5ef6bf4c8c1a..9f6176f0ba2a 100644 --- a/runtime/queries/tsq/highlights.scm +++ b/runtime/queries/tsq/highlights.scm @@ -1,50 +1,78 @@ -; mark the string passed #match? as a regex -(((predicate_name) @function - (capture) - (string) @string.regexp) - (#eq? @function "#match?")) +((predicate + name: (identifier) @_name + parameters: + (parameters + (string + "\"" @string + "\"" @string) @string.regexp + . + (string) .)) + (#any-of? @_name "gsub" "not-gsub")) -; highlight inheritance comments -(((comment) @keyword.directive) - (#match? @keyword.directive "^; +inherits *:")) +((comment) @keyword.directive + (#match? @keyword.directive "^;+\s*format\-ignore\s*$")) + +((program + . + (comment)* + . + (comment) @keyword.directive) + (#match? @keyword.directive "^;+ *extends *$")) + +((program + . + (comment)* + . + (comment) @keyword.import) + (#match? @keyword.import "^;+ *inherits *:")) + +((parameters + (identifier) @number) + (#match? @number "^[-+]?[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) @property) + +(field_definition + name: (identifier) @property) + +(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 644045570626..d793fedb026d 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" "vim-match" "not-vim-match") + (#set! injection.language "regex")) From 718afff4b9dd469b5798e1156138bd89130b90d1 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 25 Dec 2024 10:48:06 -0500 Subject: [PATCH 2/5] Use constant.numeric Co-authored-by: Michael Davis --- runtime/queries/tsq/highlights.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/queries/tsq/highlights.scm b/runtime/queries/tsq/highlights.scm index 9f6176f0ba2a..8a3a33e697ab 100644 --- a/runtime/queries/tsq/highlights.scm +++ b/runtime/queries/tsq/highlights.scm @@ -27,8 +27,8 @@ (#match? @keyword.import "^;+ *inherits *:")) ((parameters - (identifier) @number) - (#match? @number "^[-+]?[0-9]+(.[0-9]+)?$")) + (identifier) @constant.numeric) + (#match? @constant.numeric "^[-+]?[0-9]+(.[0-9]+)?$")) "_" @constant From e635736351b9d0cf2b48ea4649cc43d793d1a2c4 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Wed, 25 Dec 2024 10:48:18 -0500 Subject: [PATCH 3/5] Use variable.other.member Co-authored-by: Michael Davis --- runtime/queries/tsq/highlights.scm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/queries/tsq/highlights.scm b/runtime/queries/tsq/highlights.scm index 8a3a33e697ab..2cc2d1d8fea7 100644 --- a/runtime/queries/tsq/highlights.scm +++ b/runtime/queries/tsq/highlights.scm @@ -56,10 +56,10 @@ (negated_field "!" @operator - (identifier) @property) + (identifier) @variable.other.member) (field_definition - name: (identifier) @property) + name: (identifier) @variable.other.member) (named_node name: (identifier) @variable) From 536b847d68f55583bb787b6fa57be26720f7a9c8 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Thu, 26 Dec 2024 12:17:10 -0500 Subject: [PATCH 4/5] Remove vim-match regex injections Co-authored-by: Michael Davis --- runtime/queries/tsq/injections.scm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/queries/tsq/injections.scm b/runtime/queries/tsq/injections.scm index d793fedb026d..253a9bdb216e 100644 --- a/runtime/queries/tsq/injections.scm +++ b/runtime/queries/tsq/injections.scm @@ -6,5 +6,5 @@ parameters: (parameters (string) @injection.content)) - (#any-of? @_name "match" "not-match" "vim-match" "not-vim-match") + (#any-of? @_name "match" "not-match") (#set! injection.language "regex")) From 76908d70e05b7cff61065244e76c15ed87b02fe9 Mon Sep 17 00:00:00 2001 From: uncenter <47499684+uncenter@users.noreply.github.com> Date: Thu, 26 Dec 2024 12:17:51 -0500 Subject: [PATCH 5/5] Remove neovim-specific query stuff --- runtime/queries/tsq/highlights.scm | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/runtime/queries/tsq/highlights.scm b/runtime/queries/tsq/highlights.scm index 2cc2d1d8fea7..67d2274483b0 100644 --- a/runtime/queries/tsq/highlights.scm +++ b/runtime/queries/tsq/highlights.scm @@ -1,24 +1,3 @@ -((predicate - name: (identifier) @_name - parameters: - (parameters - (string - "\"" @string - "\"" @string) @string.regexp - . - (string) .)) - (#any-of? @_name "gsub" "not-gsub")) - -((comment) @keyword.directive - (#match? @keyword.directive "^;+\s*format\-ignore\s*$")) - -((program - . - (comment)* - . - (comment) @keyword.directive) - (#match? @keyword.directive "^;+ *extends *$")) - ((program . (comment)*