From 3658e97c2ba41530b36ab7e200c53b854d6a5fa1 Mon Sep 17 00:00:00 2001 From: Bryce Berger Date: Wed, 16 Jul 2025 09:36:54 -0400 Subject: [PATCH] Add tree-sitter injections for jj config files (#13926) --- book/src/generated/lang-support.md | 3 +++ languages.toml | 28 +++++++++++++++++++++++ runtime/queries/jjconfig/highlights.scm | 1 + runtime/queries/jjconfig/indents.scm | 1 + runtime/queries/jjconfig/injections.scm | 10 ++++++++ runtime/queries/jjconfig/textobjects.scm | 1 + runtime/queries/jjrevset/highlights.scm | 18 +++++++++++++++ runtime/queries/jjtemplate/highlights.scm | 14 ++++++++++++ 8 files changed, 76 insertions(+) create mode 100644 runtime/queries/jjconfig/highlights.scm create mode 100644 runtime/queries/jjconfig/indents.scm create mode 100644 runtime/queries/jjconfig/injections.scm create mode 100644 runtime/queries/jjconfig/textobjects.scm create mode 100644 runtime/queries/jjrevset/highlights.scm create mode 100644 runtime/queries/jjtemplate/highlights.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index 1c620e374..b16e98626 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -117,7 +117,10 @@ | java | ✓ | ✓ | ✓ | `jdtls` | | javascript | ✓ | ✓ | ✓ | `typescript-language-server` | | jinja | ✓ | | | | +| jjconfig | ✓ | ✓ | ✓ | `taplo`, `tombi` | | jjdescription | ✓ | | | | +| jjrevset | ✓ | | | | +| jjtemplate | ✓ | | | | | jq | ✓ | ✓ | | `jq-lsp` | | jsdoc | ✓ | | | | | json | ✓ | ✓ | ✓ | `vscode-json-language-server` | diff --git a/languages.toml b/languages.toml index 670904fed..a2f0c9d93 100644 --- a/languages.toml +++ b/languages.toml @@ -3541,6 +3541,16 @@ block-comment-tokens = { start = "{#", end = "#}" } name = "jinja2" source = { git = "https://github.com/varpeti/tree-sitter-jinja2", rev = "a533cd3c33aea6acb0f9bf9a56f35dcfe6a8eb53" } +[[language]] +name = "jjconfig" +scope = "source.jjconfig" +injection-regex = "jjconfig" +grammar = "toml" +file-types = [{ glob = "jj/config.toml" }, { glob = "jj/conf.d/*.toml" }, { glob = ".jj/repo/*.toml" }] +comment-token = "#" +language-servers = [ "taplo", "tombi" ] +indent = { tab-width = 2, unit = " " } + [[language]] name = "jjdescription" scope = "jj.description" @@ -3554,6 +3564,24 @@ text-width = 72 name = "jjdescription" source = { git = "https://github.com/kareigu/tree-sitter-jjdescription", rev = "1613b8c85b6ead48464d73668f39910dcbb41911" } +[[language]] +name = "jjrevset" +scope = "jj.revset" +file-types = ["jjrevset"] + +[[grammar]] +name = "jjrevset" +source = { git = "https://github.com/bryceberger/tree-sitter-jjrevset", rev = "d9af23944b884ec528b505f41d81923bb3136a51" } + +[[language]] +name = "jjtemplate" +scope = "jj.template" +file-types = ["jjtemplate"] + +[[grammar]] +name = "jjtemplate" +source = { git = "https://github.com/bryceberger/tree-sitter-jjtemplate", rev = "4313eda8ac31c60e550e3ad5841b100a0a686715" } + [[language]] name = "jq" scope = "source.jq" diff --git a/runtime/queries/jjconfig/highlights.scm b/runtime/queries/jjconfig/highlights.scm new file mode 100644 index 000000000..b55e36da4 --- /dev/null +++ b/runtime/queries/jjconfig/highlights.scm @@ -0,0 +1 @@ +; inherits: toml diff --git a/runtime/queries/jjconfig/indents.scm b/runtime/queries/jjconfig/indents.scm new file mode 100644 index 000000000..b55e36da4 --- /dev/null +++ b/runtime/queries/jjconfig/indents.scm @@ -0,0 +1 @@ +; inherits: toml diff --git a/runtime/queries/jjconfig/injections.scm b/runtime/queries/jjconfig/injections.scm new file mode 100644 index 000000000..7add16130 --- /dev/null +++ b/runtime/queries/jjconfig/injections.scm @@ -0,0 +1,10 @@ +((comment) @injection.content + (#set! injection.language "comment")) + +(table + (bare_key) @table-name (#any-of? @table-name "templates" "template-aliases") + [(pair (_) ((string) @injection.content (#set! injection.language "jjtemplate"))) (comment)]*) + +(table + (bare_key) @table-name (#any-of? @table-name "revsets" "revset-aliases") + [(pair (_) ((string) @injection.content (#set! injection.language "jjrevset"))) (comment)]*) diff --git a/runtime/queries/jjconfig/textobjects.scm b/runtime/queries/jjconfig/textobjects.scm new file mode 100644 index 000000000..b55e36da4 --- /dev/null +++ b/runtime/queries/jjconfig/textobjects.scm @@ -0,0 +1 @@ +; inherits: toml diff --git a/runtime/queries/jjrevset/highlights.scm b/runtime/queries/jjrevset/highlights.scm new file mode 100644 index 000000000..4bd07f5d7 --- /dev/null +++ b/runtime/queries/jjrevset/highlights.scm @@ -0,0 +1,18 @@ +(at_op) @variable.builtin + +[ + "::" ".." + (negate_op) + (union_op) (intersection_op) (difference_op) +] @operator + +["(" ")"] @punctuation.bracket +"," @punctuation.delimiter +[(raw_string_literal) (string_literal)] @string + +(function ((strict_identifier) @function)) +(function (function_arguments (keyword_argument (strict_identifier) @variable.parameter))) + +(primary ((identifier) @variable)) + +(string_pattern (strict_identifier) @keyword) diff --git a/runtime/queries/jjtemplate/highlights.scm b/runtime/queries/jjtemplate/highlights.scm new file mode 100644 index 000000000..cb75a7f92 --- /dev/null +++ b/runtime/queries/jjtemplate/highlights.scm @@ -0,0 +1,14 @@ +(function ((identifier) @function)) +; method calls +(term (_) ("." @punctuation) ((function ((identifier) @function.method)))) + +["(" ")"] @punctuation.bracket +"," @punctuation.delimiter + +((identifier) @keyword.control.conditional (#eq? @keyword.control.conditional "if")) +((identifier) @keyword.control.repeat (#eq? @keyword.control.repeat "for")) + +(term ((identifier) @variable)) + +[(infix_ops) "++"] @operator +[(string_literal) (raw_string_literal)] @string