From fee71c102c54146f90b14c89711ddbb8f95a1484 Mon Sep 17 00:00:00 2001 From: osthomas <8322329+osthomas@users.noreply.github.com> Date: Sun, 7 Sep 2025 13:58:28 +0200 Subject: feat(snakemake): update queries (#8106) also add indent tests --- runtime/queries/snakemake/highlights.scm | 8 +++---- runtime/queries/snakemake/indents.scm | 40 +++++++++++++++++++------------- runtime/queries/snakemake/locals.scm | 36 ++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 20 deletions(-) (limited to 'runtime') diff --git a/runtime/queries/snakemake/highlights.scm b/runtime/queries/snakemake/highlights.scm index 8781b405c..59a180c44 100644 --- a/runtime/queries/snakemake/highlights.scm +++ b/runtime/queries/snakemake/highlights.scm @@ -63,20 +63,20 @@ body: (_ ; directive labels in wildcard context ((wildcard (identifier) @label) - (#any-of? @label "input" "log" "output" "params" "resources" "threads" "wildcards")) + (#any-of? @label "input" "jobid" "log" "output" "params" "resources" "rule" "threads" "wildcards")) ((wildcard (attribute object: (identifier) @label)) - (#any-of? @label "input" "log" "output" "params" "resources" "threads" "wildcards")) + (#any-of? @label "input" "jobid" "log" "output" "params" "resources" "rule" "threads" "wildcards")) ((wildcard (subscript value: (identifier) @label)) - (#any-of? @label "input" "log" "output" "params" "resources" "threads" "wildcards")) + (#any-of? @label "input" "jobid" "log" "output" "params" "resources" "rule" "threads" "wildcards")) ; directive labels in block context (eg. within 'run:') ((identifier) @label - (#any-of? @label "input" "log" "output" "params" "resources" "threads" "wildcards") + (#any-of? @label "input" "jobid" "log" "output" "params" "resources" "rule" "threads" "wildcards") (#has-ancestor? @label "directive") (#has-ancestor? @label "block")) diff --git a/runtime/queries/snakemake/indents.scm b/runtime/queries/snakemake/indents.scm index 140b7fb3c..d4ed63992 100644 --- a/runtime/queries/snakemake/indents.scm +++ b/runtime/queries/snakemake/indents.scm @@ -1,12 +1,12 @@ ; inherits: python -((rule_definition) @indent.begin - (#set! indent.immediate 1)) - -((checkpoint_definition) @indent.begin - (#set! indent.immediate 1)) - -((rule_inheritance) @indent.begin +([ + (rule_definition) + (checkpoint_definition) + (rule_inheritance) + (module_definition) + (directive) +] @indent.begin (#set! indent.immediate 1)) ((rule_import @@ -14,12 +14,20 @@ ":") @indent.begin (#set! indent.immediate 1)) -((module_definition) @indent.begin - (#set! indent.immediate 1)) - -((directive) @indent.begin - (#set! indent.immediate 1)) - -; end indentation after last parameter node (no following ',') -(directive_parameters - (_) @indent.end .) +; ; end indentation after last parameter node (no following ',') +; ; accommodate different levels of nesting +; ; see also queries/python/indents.scm: return_statement +(directive + (directive_parameters + [ + (_) @indent.dedent + (_ + [ + (_) + ")" + "}" + "]" + ] .) @indent.dedent + ] + . ; anchor at end: no subsequent ',' + )) diff --git a/runtime/queries/snakemake/locals.scm b/runtime/queries/snakemake/locals.scm index 219f23347..8b5e7c0b4 100644 --- a/runtime/queries/snakemake/locals.scm +++ b/runtime/queries/snakemake/locals.scm @@ -2,3 +2,39 @@ (rule_definition name: (identifier) @local.definition.type) @local.scope + +(rule_inheritance + alias: (as_pattern_target) @local.definition.type) @local.scope + +(checkpoint_definition + name: (identifier) @local.definition.type) @local.scope + +(module_definition + name: (identifier) @local.definition.type) @local.scope + +; use rule A from X +(rule_import + (rule_import_list + (identifier) @local.definition.import) + . + module_name: (identifier) .) @local.scope + +; use rule A from X as A_fromX +; use rule A from X as *_fromX +; use rule * from X as *_fromX +(rule_import + alias: (as_pattern_target) @local.definition.import .) @local.scope + +; use rule A from X with: +(rule_import + (rule_import_list + (identifier) @local.definition.type) + . + module_name: (identifier) + . + "with") @local.scope + +; use rule A from X as Y with: +(rule_import + alias: (as_pattern_target) @local.definition.type + "with") @local.scope -- cgit v1.2.3-70-g09d2