Skip to content

Commit

Permalink
Features/#408 unexpected sections (#417)
Browse files Browse the repository at this point in the history
feat: Inspection: Show ERROR for execution sections in 'use' section (#408)
  • Loading branch information
dakochik authored Aug 16, 2021
1 parent eaab037 commit 7e95233
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 46 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Released on ...
- Ability for memorising new section name (see [#372](https://github.com/JetBrains-Research/snakecharm/issues/372))
- Support for 'handover' section (see [#362](https://github.com/JetBrains-Research/snakecharm/issues/362))
- Support for 'containerized' section (see [#361](https://github.com/JetBrains-Research/snakecharm/issues/361))
- Inspection: Show ERROR for execution sections in 'use' section (see [#408](https://github.com/JetBrains-Research/snakecharm/issues/408))
- Completion features related to 'use' section (see [#413](https://github.com/JetBrains-Research/snakecharm/issues/413))
- Add reference for 'snakefile:' in module declaration (see [#409](https://github.com/JetBrains-Research/snakecharm/issues/409))
- TODO (see [#NNN](https://github.com/JetBrains-Research/snakecharm/issues/NNN))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.jetbrains.snakecharm.inspections

import com.intellij.codeInspection.LocalInspectionToolSession
import com.intellij.codeInspection.ProblemsHolder
import com.jetbrains.snakecharm.SnakemakeBundle
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI
import com.jetbrains.snakecharm.lang.SnakemakeNames
import com.jetbrains.snakecharm.lang.psi.*

class SmkExecutionSubsectionInUseSectionInspection : SnakemakeInspection() {
override fun buildVisitor(
holder: ProblemsHolder,
isOnTheFly: Boolean,
session: LocalInspectionToolSession
) = object : SnakemakeInspectionVisitor(holder, session) {

override fun visitSmkRuleOrCheckpointArgsSection(st: SmkRuleOrCheckpointArgsSection) {
val sectionNamePsi = st.nameIdentifier
val sectionKeyword = st.sectionKeyword
if (st.getParentRuleOrCheckPoint() is SmkUse &&
sectionKeyword in (SnakemakeAPI.EXECUTION_SECTIONS_KEYWORDS + SnakemakeNames.SECTION_RUN)
) {
registerProblem(sectionNamePsi, SnakemakeBundle.message("INSP.NAME.unexpected.execution.section"))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package com.jetbrains.snakecharm.inspections

import com.intellij.codeInspection.LocalInspectionToolSession
import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.codeInspection.ProblemsHolder
import com.intellij.psi.util.elementType
import com.intellij.codeInspection.ui.ListEditForm
import com.jetbrains.snakecharm.SnakemakeBundle
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.EXECUTION_SECTIONS_KEYWORDS
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.MODULE_SECTIONS_KEYWORDS
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.RULE_OR_CHECKPOINT_ARGS_SECTION_KEYWORDS
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.SUBWORKFLOW_SECTIONS_KEYWORDS
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.USE_SECTIONS_KEYWORDS
import com.jetbrains.snakecharm.lang.psi.*
import com.jetbrains.snakecharm.lang.psi.elementTypes.SmkElementTypes
import com.jetbrains.snakecharm.inspections.quickfix.AddIgnoredElementQuickFix
import com.jetbrains.snakecharm.lang.SnakemakeNames.SECTION_RUN
import javax.swing.JComponent

class SmkUnrecognizedSectionInspection : SnakemakeInspection() {
Expand Down Expand Up @@ -52,13 +53,13 @@ class SmkUnrecognizedSectionInspection : SnakemakeInspection() {
val sectionKeyword = argsSection.sectionKeyword

if (sectionNamePsi != null && sectionKeyword != null && sectionKeyword !in setOfValidNames
&& sectionKeyword !in ignoredItems
&& sectionKeyword !in ignoredItems && !(argsSection.getParentRuleOrCheckPoint() is SmkUse
&& sectionKeyword in (EXECUTION_SECTIONS_KEYWORDS + SECTION_RUN))
) {
registerProblem(
sectionNamePsi,
SnakemakeBundle.message("INSP.NAME.section.unrecognized.message", sectionKeyword),
ProblemHighlightType.WEAK_WARNING,
null, AddIgnoredElementQuickFix(sectionKeyword)
AddIgnoredElementQuickFix(sectionKeyword)
)
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@
implementationClass="com.jetbrains.snakecharm.inspections.SmkUnrecognizedSectionInspection"
/>

<localInspection
language="Snakemake" shortName="SmkExecutionSubsectionInUseSectionInspection"
enabledByDefault="true"
level="ERROR"
suppressId="SmkExecutionSubsectionInUseSection"
bundle="SnakemakeBundle"
groupKey="INSP.GROUP.snakemake"
key="INSP.NAME.unexpected.execution.section"
implementationClass="com.jetbrains.snakecharm.inspections.SmkExecutionSubsectionInUseSectionInspection"
/>

<localInspection
language="Snakemake" shortName="SmkUnusedLogFileInspection"
enabledByDefault="true"
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/SnakemakeBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ INSP.NAME.section.unrecognized.message=Section ''{0}'' isn''t recognized by Snak
INSP.NAME.section.unrecognized.ignored=Ignored Sections
INSP.NAME.section.unrecognized.ignored.add=Ignore an unrecognized section ''{0}''

# SmkExecutionSubsectionInUseSectionInspection
INSP.NAME.unexpected.execution.section=Execution sections can't be overridden in 'use rule'

# SmkUnusedLogFileInspection
INSP.NAME.unused.log.section=Looks like a log file won't be created, because it is not referenced from 'shell' or 'run' sections
INSP.INTN.unused.log.fix.add.to.shell.section=Append "{0}" to shell section command
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<html>
<body>
This inspection highlights the sections which can't be overridden in 'use rule' ('shell', 'script',
'notebook', 'cwl' and 'run' sections).
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Feature: Inspection if subsection is unexpected for section but it i appropriate for another section

Scenario: 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"
"""
And SmkExecutionSubsectionInUseSectionInspection inspection is enabled
Then I expect inspection error on <run> with message
"""
Execution sections can't be overridden in 'use rule'
"""
Then I expect inspection error on <shell> with message
"""
Execution sections can't be overridden in 'use rule'
"""
Then I expect inspection error on <notebook> with message
"""
Execution sections can't be overridden in 'use rule'
"""
Then I expect inspection error on <script> with message
"""
Execution sections can't be overridden in 'use rule'
"""
Then I expect inspection error on <cwl> with message
"""
Execution sections can't be overridden in 'use rule'
"""
Then I expect inspection error on <wrapper> with message
"""
Execution sections can't be overridden in 'use rule'
"""
When I check highlighting errors
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@ Feature: Inspection if section isn't recognized by SnakeCharm
| subworkflow |
| checkpoint |

Scenario Outline: When quick fix is, applied check no warning
Given a snakemake project
Given I open a file "foo.smk" with text
Scenario Outline: When quick fix is, applied check no warning
Given a snakemake project
Given I open a file "foo.smk" with text
"""
<rule_like>:
unknown_section: ""
"""
And SmkUnrecognizedSectionInspection inspection is enabled
And I emulate quick fix apply: ignore unresolved item 'unknown_section'
Then I expect no inspection weak warnings
When I check highlighting weak warnings
Examples:
| rule_like |
| rule |
| subworkflow |
| checkpoint |
And SmkUnrecognizedSectionInspection inspection is enabled
And I emulate quick fix apply: ignore unresolved item 'unknown_section'
Then I expect no inspection weak warnings
When I check highlighting weak warnings
Examples:
| rule_like |
| rule |
| subworkflow |
| checkpoint |

Scenario Outline: When quick fix is applied, check such element in ignored list
Given a snakemake project
Expand All @@ -60,41 +60,24 @@ Feature: Inspection if section isn't recognized by SnakeCharm
| subworkflow |
| checkpoint |

Scenario: When 'use' section contains execution subsections
Given a snakemake project
Given I open a file "foo.smk" with text
Scenario: No weak warnings on execution sections in 'use rule'
Given a snakemake project
Given I open a file "foo.smk" with text
"""
use rule RULE as NEW_RULE with:
rule A:
threads: 4
use rule A as B with:
run: ""
shell: ""
notebook: ""
input: "file1"
script: ""
cwl: ""
wrapper: ""
output: "file2"
"""
And SmkUnrecognizedSectionInspection inspection is enabled
Then I expect inspection weak warning on <run> with message
"""
Section 'run' isn't recognized by SnakeCharm plugin or there could be a typo in the section name.
"""
Then I expect inspection weak warning on <shell> with message
"""
Section 'shell' isn't recognized by SnakeCharm plugin or there could be a typo in the section name.
"""
Then I expect inspection weak warning on <notebook> with message
"""
Section 'notebook' isn't recognized by SnakeCharm plugin or there could be a typo in the section name.
"""
Then I expect inspection weak warning on <script> with message
"""
Section 'script' isn't recognized by SnakeCharm plugin or there could be a typo in the section name.
"""
Then I expect inspection weak warning on <cwl> with message
"""
Section 'cwl' isn't recognized by SnakeCharm plugin or there could be a typo in the section name.
"""
Then I expect inspection weak warning on <wrapper> with message
"""
Section 'wrapper' isn't recognized by SnakeCharm plugin or there could be a typo in the section name.
"""
When I check highlighting weak warnings
And SmkUnrecognizedSectionInspection inspection is enabled
And I emulate quick fix apply: ignore unresolved item 'unknown_section'
Then I expect no inspection weak warnings
When I check highlighting weak warnings

0 comments on commit 7e95233

Please sign in to comment.