Unnamed repository; edit this file 'description' to name the repository.
feat: Add support for cylc configuration files (#11830)
Co-authored-by: Michael Davis <[email protected]>
Elliot Fontaine 2024-10-31
parent 101a74b · commit 38faf74
-rw-r--r--book/src/generated/lang-support.md1
-rw-r--r--languages.toml13
-rw-r--r--runtime/queries/cylc/highlights.scm100
-rw-r--r--runtime/queries/cylc/indents.scm19
-rw-r--r--runtime/queries/cylc/injections.scm20
-rw-r--r--runtime/queries/cylc/textobjects.scm23
6 files changed, 175 insertions, 1 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index 4f9b64de..09f15b37 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -29,6 +29,7 @@
| crystal | ✓ | ✓ | | `crystalline` |
| css | ✓ | | ✓ | `vscode-css-language-server` |
| cue | ✓ | | | `cuelsp` |
+| cylc | ✓ | ✓ | ✓ | |
| d | ✓ | ✓ | ✓ | `serve-d` |
| dart | ✓ | ✓ | ✓ | `dart` |
| dbml | ✓ | | | |
diff --git a/languages.toml b/languages.toml
index 57d220b6..3d4d1f90 100644
--- a/languages.toml
+++ b/languages.toml
@@ -3845,7 +3845,18 @@ comment-tokens = ["#", "##"]
indent = { tab-width = 2, unit = " " }
language-servers = ["pylsp" ]
-
[[grammar]]
name = "snakemake"
source = { git = "https://github.com/osthomas/tree-sitter-snakemake", rev = "e909815acdbe37e69440261ebb1091ed52e1dec6" }
+
+[[language]]
+name = "cylc"
+scope = "source.cylc"
+injection-regex = "cylc"
+file-types = ["cylc", { glob = "suite.rc" }]
+comment-tokens = "#"
+indent = { tab-width = 4, unit = " " }
+
+[[grammar]]
+name = "cylc"
+source = { git = "https://github.com/elliotfontaine/tree-sitter-cylc", rev = "30dd40d9bf23912e4aefa93eeb4c7090bda3d0f6" } \ No newline at end of file
diff --git a/runtime/queries/cylc/highlights.scm b/runtime/queries/cylc/highlights.scm
new file mode 100644
index 00000000..e9e1194f
--- /dev/null
+++ b/runtime/queries/cylc/highlights.scm
@@ -0,0 +1,100 @@
+(ERROR) @markup.bold
+
+[
+ (jinja2_expression)
+ (jinja2_statement)
+ (jinja2_comment)
+ (jinja2_shebang)
+] @special
+
+(include_statement
+ directive: _ @keyword.directive
+ path: _ @string.special.path)
+
+(comment) @comment.line
+
+(graph_section
+ name: _? @label)
+
+(task_section
+ name: (_
+ (task_name) @namespace))
+
+(top_section
+ brackets_open: _ @punctuation.bracket
+ name: _? @label
+ brackets_close: _ @punctuation.bracket)
+
+(sub_section_1
+ brackets_open: _ @punctuation.bracket
+ name: _? @label
+ brackets_close: _ @punctuation.bracket)
+
+(sub_section_2
+ brackets_open: _ @punctuation.bracket
+ name: _? @label
+ brackets_close: _ @punctuation.bracket)
+
+(runtime_section
+ brackets_open: _ @punctuation.bracket
+ name: _? @label
+ brackets_close: _ @punctuation.bracket)
+
+(graph_setting
+ key: (_) @constant.numeric.integer
+ operator: (_)? @operator)
+
+(quoted_graph_string
+ quotes_open: _ @string
+ quotes_close: _ @string)
+
+(multiline_graph_string
+ quotes_open: _ @string
+ quotes_close: _ @string)
+
+[
+ (graph_logical)
+ (graph_arrow)
+ (graph_parenthesis)
+] @operator
+
+(intercycle_annotation
+ (recurrence) @constant.numeric.integer)
+
+(graph_task
+ xtrigger: _? @operator
+ suicide: _? @operator
+ name: _ @namespace)
+
+(task_parameter
+ "<" @tag
+ name: (_)? @special
+ ","? @tag
+ "="? @tag
+ selection: (_)? @special
+ ">" @tag)
+
+(intercycle_annotation
+ "[" @tag
+ (recurrence)? @constant.numeric.integer
+ "]" @tag)
+
+(task_output
+ ":" @tag
+ (nametag) @variable.other)
+
+(task_output
+ "?"? @tag)
+
+(setting
+ key: (key) @variable
+ operator: (_)? @operator
+ value: [
+ (unquoted_string) @string
+ (quoted_string) @string
+ (multiline_string) @string
+ (boolean) @constant.builtin.boolean
+ (integer) @constant.numeric.integer
+ ]?)
+
+(datetime) @constant.numeric.float
diff --git a/runtime/queries/cylc/indents.scm b/runtime/queries/cylc/indents.scm
new file mode 100644
index 00000000..865386c7
--- /dev/null
+++ b/runtime/queries/cylc/indents.scm
@@ -0,0 +1,19 @@
+[
+ (top_section)
+ (sub_section_1)
+ (sub_section_2)
+ (graph_section)
+ (runtime_section)
+ (task_section)
+] @indent
+
+[
+ (top_section)
+ (sub_section_1)
+ (sub_section_2)
+ (graph_section)
+ (runtime_section)
+ (task_section)
+] @extend
+
+(line_continuation) @indent.always
diff --git a/runtime/queries/cylc/injections.scm b/runtime/queries/cylc/injections.scm
new file mode 100644
index 00000000..d10931f4
--- /dev/null
+++ b/runtime/queries/cylc/injections.scm
@@ -0,0 +1,20 @@
+((setting
+ key: (key) @key
+ (#match? @key "^script$|-script$|^script-")
+ value: (_
+ (string_content) @injection.content))
+ (#set! "injection.language" "bash"))
+
+; Requires no spacing around "=" in environment settings for proper highlighting.
+; Could be improved if Tree-sitter allowed to specify the target node of the injected
+; language, instead of always using the root node.
+; See this proposal:
+; https://github.com/tree-sitter/tree-sitter/issues/3625
+((task_section
+ (sub_section_2
+ name: (_) @section_name
+ (#eq? @section_name "environment")
+ (setting) @injection.content))
+ (#set! "injection.language" "bash")
+ (#set! injection.combined)
+ (#set! injection.include-children))
diff --git a/runtime/queries/cylc/textobjects.scm b/runtime/queries/cylc/textobjects.scm
new file mode 100644
index 00000000..00ed52ff
--- /dev/null
+++ b/runtime/queries/cylc/textobjects.scm
@@ -0,0 +1,23 @@
+(comment) @comment.inside
+
+(comment)+ @comment.around
+
+(_
+ brackets_open: _
+ name: _?
+ brackets_close: _
+ _* @class.inside) @class.around
+
+(setting
+ value: _? @function.inside) @function.around
+
+(graph_setting
+ value: _? @function.inside) @function.around
+
+(graph_string_content
+ (graph_task) @entry.inside)
+
+(task_parameter
+ ((_) @parameter.inside
+ .
+ ","? @parameter.around) @parameter.around)