From 197f1893855dc6388bd2bc25916da0ead1536d18 Mon Sep 17 00:00:00 2001 From: Roman Chernyatchik Date: Wed, 3 Aug 2022 20:00:38 +0200 Subject: [PATCH] feat: [7.0.0] template_engine: basic support #497 1) highlight template_engine as known section 2) Only one argument expected after `template_engine` 3) Keywords arguments not supported after `template_engine` 4) Do not warn about unused log section if rule wiht `template_engine` 5) `template_engine` is execution section, so could not be with run/shell/notebook/script 6) `template_engine` should be last in the rule 7) no smksl template injection in `template_engine` Resolves: #497 --- CHANGELOG.md | 1 + .../snakecharm/codeInsight/SnakemakeAPI.kt | 18 +++-- .../snakecharm/lang/SnakemakeNames.kt | 1 + ...mkRuleSectionAfterExecutionInspection.html | 2 +- .../lang/parser/SnakemakeParsingTest.kt | 4 + .../completion/keywords_completion.feature | 77 ++++++++++--------- .../smkl_in_section_completion.feature | 1 + ...bsection_in_use_section_inspection.feature | 42 ++++------ .../multiple_args_inspection.feature | 47 +++++------ ...e_keywords_after_execution_section.feature | 15 ++-- ...unexpected_keyword_args_inspection.feature | 1 + .../unused_log_section_inspection.feature | 14 ++-- .../highlighting/smk_syntax_annotator.feature | 1 + .../smk_syntax_error_annotator.feature | 15 ++-- .../string_language_injection.feature | 1 + testData/psi/RuleSectionTemplateEngine.smk | 3 + testData/psi/RuleSectionTemplateEngine.txt | 15 ++++ 17 files changed, 142 insertions(+), 116 deletions(-) create mode 100644 testData/psi/RuleSectionTemplateEngine.smk create mode 100644 testData/psi/RuleSectionTemplateEngine.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index d9a6b6289..17a46f64e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Released on ... ### Added: - [7.10.0] Support conda environment definitions to be passed as function pointers, similar to input, params, and resources #494 (see [#494](https://github.com/JetBrains-Research/snakecharm/issues/494)) - [7.9.0] Syntax supprt for `exclude` keyword in use rules (see [#495](https://github.com/JetBrains-Research/snakecharm/issues/495), [#496](https://github.com/JetBrains-Research/snakecharm/issues/496)) +- [ 7.0.0] template_engine: basic support (see [#497](https://github.com/JetBrains-Research/snakecharm/issues/497)) - TODO (see [#NNN](https://github.com/JetBrains-Research/snakecharm/issues/NNN)) ## [2022.1.749] diff --git a/src/main/kotlin/com/jetbrains/snakecharm/codeInsight/SnakemakeAPI.kt b/src/main/kotlin/com/jetbrains/snakecharm/codeInsight/SnakemakeAPI.kt index 4e4868cd4..383b7c07d 100644 --- a/src/main/kotlin/com/jetbrains/snakecharm/codeInsight/SnakemakeAPI.kt +++ b/src/main/kotlin/com/jetbrains/snakecharm/codeInsight/SnakemakeAPI.kt @@ -32,6 +32,7 @@ import com.jetbrains.snakecharm.lang.SnakemakeNames.SECTION_SCRIPT import com.jetbrains.snakecharm.lang.SnakemakeNames.SECTION_SHADOW import com.jetbrains.snakecharm.lang.SnakemakeNames.SECTION_SHELL import com.jetbrains.snakecharm.lang.SnakemakeNames.SECTION_SINGULARITY +import com.jetbrains.snakecharm.lang.SnakemakeNames.SECTION_TEMPLATE_ENGINE import com.jetbrains.snakecharm.lang.SnakemakeNames.SECTION_THREADS import com.jetbrains.snakecharm.lang.SnakemakeNames.SECTION_VERSION import com.jetbrains.snakecharm.lang.SnakemakeNames.SECTION_WILDCARD_CONSTRAINTS @@ -104,10 +105,13 @@ object SnakemakeAPI { const val SNAKEMAKE_MODULE_NAME_IO_PY = "io.py" /** - * Sections that gets 'snakemake' object with 'snakemake.input', 'snakemake.params' etc settings + * Sections that execute external script with access to 'snakemake' object, i.e to 'snakemake.input', + * 'snakemake.params' etc settings. So we cannot verify that log section mentioned in rule is + * unused. */ val EXECUTION_SECTIONS_THAT_ACCEPTS_SNAKEMAKE_PARAMS_OBJ_FROM_RULE = setOf( - SECTION_WRAPPER, SECTION_NOTEBOOK, SECTION_SCRIPT, SECTION_CWL + SECTION_WRAPPER, SECTION_NOTEBOOK, SECTION_SCRIPT, SECTION_CWL, + SECTION_TEMPLATE_ENGINE ) val EXECUTION_SECTIONS_KEYWORDS = setOf( @@ -123,7 +127,7 @@ object SnakemakeAPI { SECTION_CWL, SECTION_BENCHMARK, SECTION_VERSION, SECTION_MESSAGE, SECTION_THREADS, SECTION_SINGULARITY, SECTION_PRIORITY, SECTION_CONDA, SECTION_GROUP, - SECTION_SHADOW, SECTION_CACHE, SECTION_NOTEBOOK, SECTION_CONTAINER, + SECTION_SHADOW, SECTION_CACHE, SECTION_NOTEBOOK, SECTION_CONTAINER, SECTION_TEMPLATE_ENGINE, SECTION_HANDOVER, SECTION_CONTAINERIZED, SECTION_DEFAULT_TARGET, SECTION_RETRIES @@ -160,7 +164,7 @@ object SnakemakeAPI { SECTION_BENCHMARK, SECTION_VERSION, SECTION_MESSAGE, SECTION_SHELL, SECTION_THREADS, SECTION_SINGULARITY, SECTION_PRIORITY, SECTION_WILDCARD_CONSTRAINTS, SECTION_GROUP, SECTION_SHADOW, SECTION_CONDA, - SECTION_SCRIPT, SECTION_WRAPPER, SECTION_CWL, SECTION_NOTEBOOK, + SECTION_SCRIPT, SECTION_WRAPPER, SECTION_CWL, SECTION_NOTEBOOK, SECTION_TEMPLATE_ENGINE, SECTION_CACHE, SECTION_CONTAINER, SECTION_CONTAINERIZED, @@ -247,7 +251,8 @@ object SnakemakeAPI { SECTION_PRIORITY, SECTION_SINGULARITY, SECTION_CACHE, SECTION_CONTAINER, SECTION_CONTAINERIZED, SECTION_NOTEBOOK, SECTION_ENVMODULES, SECTION_HANDOVER, SECTION_DEFAULT_TARGET, - SECTION_RETRIES + SECTION_RETRIES, + SECTION_TEMPLATE_ENGINE ) /** @@ -312,7 +317,8 @@ object SnakemakeAPI { SECTION_BENCHMARK, SECTION_VERSION, SECTION_MESSAGE, SECTION_SHELL, SECTION_THREADS, SECTION_SINGULARITY, SECTION_PRIORITY, SECTION_GROUP, SECTION_SHADOW, SECTION_CONDA, SECTION_SCRIPT, SECTION_WRAPPER, SECTION_CWL, SECTION_NOTEBOOK, SECTION_CACHE, SECTION_CONTAINER, SECTION_CONTAINERIZED, SECTION_ENVMODULES, - SECTION_NAME, SECTION_HANDOVER, SECTION_DEFAULT_TARGET, SECTION_RETRIES + SECTION_NAME, SECTION_HANDOVER, SECTION_DEFAULT_TARGET, SECTION_RETRIES, + SECTION_TEMPLATE_ENGINE ) /** diff --git a/src/main/kotlin/com/jetbrains/snakecharm/lang/SnakemakeNames.kt b/src/main/kotlin/com/jetbrains/snakecharm/lang/SnakemakeNames.kt index 6b24b96b3..166f7f22c 100644 --- a/src/main/kotlin/com/jetbrains/snakecharm/lang/SnakemakeNames.kt +++ b/src/main/kotlin/com/jetbrains/snakecharm/lang/SnakemakeNames.kt @@ -71,6 +71,7 @@ object SnakemakeNames { const val SECTION_NAME = "name" // >= 5.31 const val SECTION_HANDOVER = "handover" // >= 6.2 const val SECTION_DEFAULT_TARGET = "default_target" // >= 5.12.0 + const val SECTION_TEMPLATE_ENGINE = "template_engine" // >= 7.0.0 const val SECTION_RETRIES = "retries" // >= 7.7.0 const val RUN_SECTION_VARIABLE_RULE = "rule" diff --git a/src/main/resources/inspectionDescriptions/SmkRuleSectionAfterExecutionInspection.html b/src/main/resources/inspectionDescriptions/SmkRuleSectionAfterExecutionInspection.html index 53e539880..2fe2e62ec 100644 --- a/src/main/resources/inspectionDescriptions/SmkRuleSectionAfterExecutionInspection.html +++ b/src/main/resources/inspectionDescriptions/SmkRuleSectionAfterExecutionInspection.html @@ -1,5 +1,5 @@ -Rule sections such as input/output/params/..., cannot be used after run/shell/script/wrapper/cwl/notebook sections. +Rule sections such as input/output/params/..., cannot be used after run/shell/script/wrapper/cwl/notebook/template_engine sections. \ No newline at end of file diff --git a/src/test/kotlin/com/jetbrains/snakecharm/lang/parser/SnakemakeParsingTest.kt b/src/test/kotlin/com/jetbrains/snakecharm/lang/parser/SnakemakeParsingTest.kt index 9271f0f38..2405cc05a 100644 --- a/src/test/kotlin/com/jetbrains/snakecharm/lang/parser/SnakemakeParsingTest.kt +++ b/src/test/kotlin/com/jetbrains/snakecharm/lang/parser/SnakemakeParsingTest.kt @@ -337,6 +337,10 @@ class SnakemakeParsingTest : ParsingTestCase( doTest() } + fun testRuleSectionTemplateEngine() { + doTest() + } + fun testRuleSectionContainer() { doTest() } diff --git a/src/test/resources/features/completion/keywords_completion.feature b/src/test/resources/features/completion/keywords_completion.feature index 5d6c40ece..ad80c7662 100644 --- a/src/test/resources/features/completion/keywords_completion.feature +++ b/src/test/resources/features/completion/keywords_completion.feature @@ -207,44 +207,45 @@ Feature: Completion for snakemake keyword-like things : """ Examples: - | rule_like | str | result | - | rule | inp | input | - | checkpoint | inp | input | - | rule | out | output | - | checkpoint | out | output | - | rule | par | params | - | checkpoint | par | params | - | rule | lo | log | - | checkpoint | lo | log | - | rule | be | benchmark | - | checkpoint | be | benchmark | - | rule | vers | version | - | checkpoint | vers | version | - | rule | cac | cache | - | checkpoint | cac | cache | - | rule | mes | message | - | checkpoint | mes | message | - | rule | pr | priority | - | checkpoint | pr | priority | - | rule | gr | group | - | checkpoint | gr | group | - | rule | envm | envmodules | - | checkpoint | envm | envmodules | - | rule | cw | cwl | - | checkpoint | cw | cwl | - | rule | sc | script | - | checkpoint | sc | script | - | rule | run | run | - | checkpoint | run | run | - | rule | wr | wrapper | - | checkpoint | wr | wrapper | - | rule | na | name | - | checkpoint | na | name | - | rule | han | handover | - | checkpoint | han | handover | - | rule | defa | default_target | - | checkpoint | defa | default_target | - | rule | retr | retries | + | rule_like | str | result | + | rule | inp | input | + | checkpoint | inp | input | + | rule | out | output | + | checkpoint | out | output | + | rule | par | params | + | checkpoint | par | params | + | rule | lo | log | + | checkpoint | lo | log | + | rule | be | benchmark | + | checkpoint | be | benchmark | + | rule | vers | version | + | checkpoint | vers | version | + | rule | cac | cache | + | checkpoint | cac | cache | + | rule | mes | message | + | checkpoint | mes | message | + | rule | pr | priority | + | checkpoint | pr | priority | + | rule | gr | group | + | checkpoint | gr | group | + | rule | envm | envmodules | + | checkpoint | envm | envmodules | + | rule | cw | cwl | + | checkpoint | cw | cwl | + | rule | sc | script | + | checkpoint | sc | script | + | rule | run | run | + | checkpoint | run | run | + | rule | wr | wrapper | + | checkpoint | wr | wrapper | + | rule | na | name | + | checkpoint | na | name | + | rule | han | handover | + | checkpoint | han | handover | + | rule | defa | default_target | + | checkpoint | defa | default_target | + | rule | retr | retries | + | rule | temp | template_engine | Scenario Outline: Complete at rule/checkpoint/module level Given a snakemake project diff --git a/src/test/resources/features/completion/smkl_in_section_completion.feature b/src/test/resources/features/completion/smkl_in_section_completion.feature index c934200cf..95e7cb473 100644 --- a/src/test/resources/features/completion/smkl_in_section_completion.feature +++ b/src/test/resources/features/completion/smkl_in_section_completion.feature @@ -102,6 +102,7 @@ Feature: Completion for sections/variables in SmkSL injections | handover | | default_target | | retries | + | template_engine | Examples: | rule_like | signature | | rule | shell: "{ | diff --git a/src/test/resources/features/highlighting/inspections/execution_subsection_in_use_section_inspection.feature b/src/test/resources/features/highlighting/inspections/execution_subsection_in_use_section_inspection.feature index 7aedfb2d4..a59f5171e 100644 --- a/src/test/resources/features/highlighting/inspections/execution_subsection_in_use_section_inspection.feature +++ b/src/test/resources/features/highlighting/inspections/execution_subsection_in_use_section_inspection.feature @@ -1,42 +1,26 @@ Feature: Inspection if subsection is unexpected for section but it i appropriate for another section - Scenario: When 'use' section contains execution subsections + Scenario Outline: When 'use' section contains execution subsections Given a snakemake project Given I open a file "foo.smk" with text """ use rule RULE as NEW_RULE with: - run: "" - shell: "" - notebook: "" input: "file1" - script: "" - cwl: "" - wrapper: "" output: "file2" +
: "foo" """ And SmkExecutionSubsectionInUseSectionInspection inspection is enabled - Then I expect inspection error on with message + Then I expect inspection error on <
> with message """ Execution sections can't be overridden in 'use rule' """ - Then I expect inspection error on with message - """ - Execution sections can't be overridden in 'use rule' - """ - Then I expect inspection error on with message - """ - Execution sections can't be overridden in 'use rule' - """ - Then I expect inspection error on