Skip to content

Commit

Permalink
feat: Add support for cylc configuration files (helix-editor#11830)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael Davis <mcarsondavis@gmail.com>
  • Loading branch information
2 people authored and rongyi committed Nov 13, 2024
1 parent 9db73b0 commit 9342a9c
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 1 deletion.
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
| crystal ||| | `crystalline` |
| css || || `vscode-css-language-server` |
| cue || | | `cuelsp` |
| cylc |||| |
| d |||| `serve-d` |
| dart |||| `dart` |
| dbml || | | |
Expand Down
13 changes: 12 additions & 1 deletion languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
100 changes: 100 additions & 0 deletions runtime/queries/cylc/highlights.scm
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions runtime/queries/cylc/indents.scm
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions runtime/queries/cylc/injections.scm
Original file line number Diff line number Diff line change
@@ -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))
23 changes: 23 additions & 0 deletions runtime/queries/cylc/textobjects.scm
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 9342a9c

Please sign in to comment.