Unnamed repository; edit this file 'description' to name the repository.
Adding snakemake to language (#11858)
* feat: snakemake language * feat: snakemake syntax highlighting * doc: xtask docgen - snakemake * Addressed feedback: removed redundant grammar * fixed indentation * removed has-ancestor predicate --------- Co-authored-by: “SebastianDall” <“[email protected]”>
Sebastian Dall 2024-10-19
parent 855a43a · commit a145335
-rw-r--r--book/src/generated/lang-support.md1
-rw-r--r--languages.toml14
-rwxr-xr-xruntime/queries/snakemake/LICENSE20
-rwxr-xr-xruntime/queries/snakemake/folds.scm8
-rwxr-xr-xruntime/queries/snakemake/highlights.scm76
-rwxr-xr-xruntime/queries/snakemake/indents.scm27
-rwxr-xr-xruntime/queries/snakemake/injections.scm5
-rwxr-xr-xruntime/queries/snakemake/locals.scm1
8 files changed, 152 insertions, 0 deletions
diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md
index aac1e474..4f9b64de 100644
--- a/book/src/generated/lang-support.md
+++ b/book/src/generated/lang-support.md
@@ -186,6 +186,7 @@
| smali | ✓ | | ✓ | |
| smithy | ✓ | | | `cs` |
| sml | ✓ | | | |
+| snakemake | ✓ | | ✓ | `pylsp` |
| solidity | ✓ | ✓ | | `solc` |
| spicedb | ✓ | | | |
| sql | ✓ | ✓ | | |
diff --git a/languages.toml b/languages.toml
index 8ade3cf8..57d220b6 100644
--- a/languages.toml
+++ b/languages.toml
@@ -3835,3 +3835,17 @@ language-servers = ["circom-lsp"]
[[grammar]]
name = "circom"
source = { git = "https://github.com/Decurity/tree-sitter-circom", rev = "02150524228b1e6afef96949f2d6b7cc0aaf999e" }
+
+[[language]]
+name = "snakemake"
+scope = "source.snakemake"
+roots = ["Snakefile", "config.yaml", "environment.yaml", "workflow/"]
+file-types = ["smk", "Snakefile"]
+comment-tokens = ["#", "##"]
+indent = { tab-width = 2, unit = " " }
+language-servers = ["pylsp" ]
+
+
+[[grammar]]
+name = "snakemake"
+source = { git = "https://github.com/osthomas/tree-sitter-snakemake", rev = "e909815acdbe37e69440261ebb1091ed52e1dec6" }
diff --git a/runtime/queries/snakemake/LICENSE b/runtime/queries/snakemake/LICENSE
new file mode 100755
index 00000000..3dea1627
--- /dev/null
+++ b/runtime/queries/snakemake/LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2016 Max Brunsfeld
+Copyright (c) 2023 Oliver Thomas
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
+of the Software, and to permit persons to whom the Software is furnished to do
+so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/runtime/queries/snakemake/folds.scm b/runtime/queries/snakemake/folds.scm
new file mode 100755
index 00000000..d154f3cd
--- /dev/null
+++ b/runtime/queries/snakemake/folds.scm
@@ -0,0 +1,8 @@
+; inherits: python
+
+[
+ (rule_definition)
+ (rule_inheritance)
+ (module_definition)
+ (checkpoint_definition)
+] @fold
diff --git a/runtime/queries/snakemake/highlights.scm b/runtime/queries/snakemake/highlights.scm
new file mode 100755
index 00000000..18d81811
--- /dev/null
+++ b/runtime/queries/snakemake/highlights.scm
@@ -0,0 +1,76 @@
+; inherits: python
+
+; Compound directives
+[
+ "rule"
+ "checkpoint"
+ "module"
+] @keyword
+
+; Top level directives (eg. configfile, include)
+(module
+ (directive
+ name: _ @keyword))
+
+; Subordinate directives (eg. input, output)
+((_)
+ body: (_
+ (directive
+ name: _ @label)))
+
+; rule/module/checkpoint names
+(rule_definition
+ name: (identifier) @type)
+
+(module_definition
+ name: (identifier) @type)
+
+(checkpoint_definition
+ name: (identifier) @type)
+
+; Rule imports
+(rule_import
+ "use" @keyword.import
+ "rule" @keyword.import
+ "from" @keyword.import
+ "exclude"? @keyword.import
+ "as"? @keyword.import
+ "with"? @keyword.import)
+
+; Rule inheritance
+(rule_inheritance
+ "use" @keyword
+ "rule" @keyword
+ "with" @keyword)
+
+; Wildcard names
+(wildcard (identifier) @variable)
+(wildcard (flag) @variable.parameter.builtin)
+
+; builtin variables
+((identifier) @variable.builtin
+ (#any-of? @variable.builtin "checkpoints" "config" "gather" "rules" "scatter" "workflow"))
+
+; References to directive labels in wildcard interpolations
+; the #any-of? queries are moved above the #has-ancestor? queries to
+; short-circuit the potentially expensive tree traversal, if possible
+; see:
+; https://github.com/nvim-treesitter/nvim-treesitter/pull/4302#issuecomment-1685789790
+; directive labels in wildcard context
+((wildcard
+ (identifier) @label)
+ (#any-of? @label "input" "log" "output" "params" "resources" "threads" "wildcards"))
+
+((wildcard
+ (attribute
+ object: (identifier) @label))
+ (#any-of? @label "input" "log" "output" "params" "resources" "threads" "wildcards"))
+
+((wildcard
+ (subscript
+ value: (identifier) @label))
+ (#any-of? @label "input" "log" "output" "params" "resources" "threads" "wildcards"))
+
+; directive labels in block context (eg. within 'run:')
+((identifier) @label
+ (#any-of? @label "input" "log" "output" "params" "resources" "threads" "wildcards"))
diff --git a/runtime/queries/snakemake/indents.scm b/runtime/queries/snakemake/indents.scm
new file mode 100755
index 00000000..6685fccb
--- /dev/null
+++ b/runtime/queries/snakemake/indents.scm
@@ -0,0 +1,27 @@
+; inherits: python
+
+
+[
+ (rule_definition)
+ (checkpoint_definition)
+ (rule_inheritance)
+ (module_definition)
+] @indent
+
+[
+ (rule_definition)
+ (checkpoint_definition)
+ (rule_inheritance)
+ (module_definition)
+] @extend
+
+
+(directive) @indent
+(directive) @extend
+
+(rule_import
+ "with"
+ ":") @indent
+(rule_import
+ "with"
+ ":") @extend
diff --git a/runtime/queries/snakemake/injections.scm b/runtime/queries/snakemake/injections.scm
new file mode 100755
index 00000000..fa56daab
--- /dev/null
+++ b/runtime/queries/snakemake/injections.scm
@@ -0,0 +1,5 @@
+; inherits: python
+
+(wildcard
+ (constraint) @injection.content
+ (#set! injection.language "regex"))
diff --git a/runtime/queries/snakemake/locals.scm b/runtime/queries/snakemake/locals.scm
new file mode 100755
index 00000000..0b920cbf
--- /dev/null
+++ b/runtime/queries/snakemake/locals.scm
@@ -0,0 +1 @@
+; inherits: python