Unnamed repository; edit this file 'description' to name the repository.
Add tree-sitter injections for jj config files (#13926)
Bryce Berger 7 months ago
parent ab668c2 · commit 3658e97
-rw-r--r--book/src/generated/lang-support.md3
-rw-r--r--languages.toml28
-rw-r--r--runtime/queries/jjconfig/highlights.scm1
-rw-r--r--runtime/queries/jjconfig/indents.scm1
-rw-r--r--runtime/queries/jjconfig/injections.scm10
-rw-r--r--runtime/queries/jjconfig/textobjects.scm1
-rw-r--r--runtime/queries/jjrevset/highlights.scm18
-rw-r--r--runtime/queries/jjtemplate/highlights.scm14
8 files changed, 76 insertions, 0 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index 1c620e37..b16e9862 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 670904fe..a2f0c9d9 100644
--- a/languages.toml
+++ b/languages.toml
@@ -3542,6 +3542,16 @@ 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"
file-types = [{ glob = "*.jjdescription" }]
@@ -3555,6 +3565,24 @@ 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"
injection-regex = "jq"
diff --git a/runtime/queries/jjconfig/highlights.scm b/runtime/queries/jjconfig/highlights.scm
new file mode 100644
index 00000000..b55e36da
--- /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 00000000..b55e36da
--- /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 00000000..7add1613
--- /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 00000000..b55e36da
--- /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 00000000..4bd07f5d
--- /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 00000000..cb75a7f9
--- /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