Skip to content

Commit

Permalink
fixed: execution section inspection is fixed
Browse files Browse the repository at this point in the history
refactored: tests and error messages

Resolves: #408
  • Loading branch information
Dmitry Kochik committed Aug 16, 2021
1 parent e0ae895 commit 8d88ffb
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 181 deletions.
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"))
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@ 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.RULE_OR_CHECKPOINT_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.MODULE_KEYWORD
import com.jetbrains.snakecharm.lang.SnakemakeNames.RULE_KEYWORD
import com.jetbrains.snakecharm.lang.SnakemakeNames.SUBWORKFLOW_KEYWORD
import com.jetbrains.snakecharm.lang.SnakemakeNames.USE_KEYWORD
import com.jetbrains.snakecharm.lang.SnakemakeNames.SECTION_RUN
import javax.swing.JComponent

class SmkUnrecognizedSectionInspection : SnakemakeInspection() {
Expand Down Expand Up @@ -56,16 +53,14 @@ 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))
) {
val appropriateSection = getSectionBySubsection(sectionKeyword)
if (appropriateSection == null) {
registerProblem(
sectionNamePsi,
SnakemakeBundle.message("INSP.NAME.section.unrecognized.message", sectionKeyword),
AddIgnoredElementQuickFix(sectionKeyword)
)
}
registerProblem(
sectionNamePsi,
SnakemakeBundle.message("INSP.NAME.section.unrecognized.message", sectionKeyword),
AddIgnoredElementQuickFix(sectionKeyword)
)
}
}

Expand All @@ -78,15 +73,5 @@ class SmkUnrecognizedSectionInspection : SnakemakeInspection() {

override fun createOptionsPanel(): JComponent? =
ListEditForm(SnakemakeBundle.message("INSP.NAME.section.unrecognized.ignored"), ignoredItems).contentPanel

companion object {
fun getSectionBySubsection(name: String) = when (name) {
in RULE_OR_CHECKPOINT_SECTION_KEYWORDS -> RULE_KEYWORD
in SUBWORKFLOW_SECTIONS_KEYWORDS -> SUBWORKFLOW_KEYWORD
in MODULE_SECTIONS_KEYWORDS -> MODULE_KEYWORD
in USE_SECTIONS_KEYWORDS -> USE_KEYWORD
else -> null
}
}
}

8 changes: 4 additions & 4 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@
/>

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

<localInspection
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/SnakemakeBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ 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}''

# SmkUnexpectedSectionInspection
INSP.NAME.section.unexpected=Section ''{0}'' can''t be used in ''{1}'' but can be in ''{2}''
# 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
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>

This file was deleted.

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 used in 'use rule'
"""
Then I expect inspection error on <shell> with message
"""
Execution sections can't be used in 'use rule'
"""
Then I expect inspection error on <notebook> with message
"""
Execution sections can't be used in 'use rule'
"""
Then I expect inspection error on <script> with message
"""
Execution sections can't be used in 'use rule'
"""
Then I expect inspection error on <cwl> with message
"""
Execution sections can't be used in 'use rule'
"""
Then I expect inspection error on <wrapper> with message
"""
Execution sections can't be used in 'use rule'
"""
When I check highlighting errors

This file was deleted.

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 @@ -58,4 +58,26 @@ Feature: Inspection if section isn't recognized by SnakeCharm
| rule_like |
| rule |
| subworkflow |
| checkpoint |
| checkpoint |

Scenario: No weak warnings on execution sections in 'use rule'
Given a snakemake project
Given I open a file "foo.smk" with text
"""
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
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 8d88ffb

Please sign in to comment.