diff --git a/CHANGELOG.md b/CHANGELOG.md index a30a24b1..068825ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Released on ... - Default path "config/config.yaml" now supported (see [#363](https://github.com/JetBrains-Research/snakecharm/issues/363)) - Access by index to input/output sections with 'multiext' function (see [#278](https://github.com/JetBrains-Research/snakecharm/issues/278)) - Inspection: Do not show warning that rule section is unused variable if rule is defined in method (see [#385](https://github.com/JetBrains-Research/snakecharm/issues/385)) +- SOE: From UnusedLocal inspection for SnakemakeSL expression (see [#380](https://github.com/JetBrains-Research/snakecharm/issues/380)) - TODO (see [#NNN](https://github.com/JetBrains-Research/snakecharm/issues/NNN)) ### Added diff --git a/src/main/kotlin/com/jetbrains/snakecharm/inspections/SmkIgnorePyInspectionExtension.kt b/src/main/kotlin/com/jetbrains/snakecharm/inspections/SmkIgnorePyInspectionExtension.kt index 585eaca7..14a8188b 100644 --- a/src/main/kotlin/com/jetbrains/snakecharm/inspections/SmkIgnorePyInspectionExtension.kt +++ b/src/main/kotlin/com/jetbrains/snakecharm/inspections/SmkIgnorePyInspectionExtension.kt @@ -47,9 +47,11 @@ class SmkIgnorePyInspectionExtension : PyInspectionExtension() { // ignoreInitNewSignatures override fun ignoreUnused(local: PsiElement?, evalContext: TypeEvalContext): Boolean { - if (local is SmkRuleOrCheckpointArgsSection) { - return true - } + // If inspection is suppressed, SOE: in Parser #380 not happen + // temporary turn off suppressing +// if (local is SmkRuleOrCheckpointArgsSection) { +// return true +// } return false } } diff --git a/src/main/kotlin/com/jetbrains/snakecharm/stringLanguage/lang/psi/SmkSLSubscriptionExpression.kt b/src/main/kotlin/com/jetbrains/snakecharm/stringLanguage/lang/psi/SmkSLSubscriptionExpression.kt index ccb95f6f..58fd2d20 100644 --- a/src/main/kotlin/com/jetbrains/snakecharm/stringLanguage/lang/psi/SmkSLSubscriptionExpression.kt +++ b/src/main/kotlin/com/jetbrains/snakecharm/stringLanguage/lang/psi/SmkSLSubscriptionExpression.kt @@ -2,6 +2,7 @@ package com.jetbrains.snakecharm.stringLanguage.lang.psi import com.intellij.lang.ASTNode import com.jetbrains.python.psi.PyElementVisitor +import com.jetbrains.python.psi.impl.PyReferenceExpressionImpl import com.jetbrains.python.psi.types.PyType import com.jetbrains.python.psi.types.TypeEvalContext import com.jetbrains.snakecharm.lang.psi.BaseSmkSLReferenceExpression @@ -10,9 +11,12 @@ import com.jetbrains.snakecharm.stringLanguage.lang.SmkSLElementVisitor /** * Not reference expression */ -class SmkSLSubscriptionExpression(node: ASTNode) : SmkSLElementImpl(node), SmkSLExpression { +// TODO PySubscriptionExpression +class SmkSLSubscriptionExpression(node: ASTNode) : PyReferenceExpressionImpl(node), BaseSmkSLReferenceExpression { override fun getType(context: TypeEvalContext, key: TypeEvalContext.Key): PyType? = null +// override fun getNameElement() = node.findChildByType(SmkSLTokenTypes.ACCESS_KEY) + override fun acceptPyVisitor(pyVisitor: PyElementVisitor) = when (pyVisitor) { is SmkSLElementVisitor -> pyVisitor.visitSmkSLSubscriptionExpression(this) else -> super.acceptPyVisitor(pyVisitor) diff --git a/src/main/kotlin/com/jetbrains/snakecharm/stringLanguage/lang/psi/SmkSLSubscriptionKeyReferenceExpression.kt b/src/main/kotlin/com/jetbrains/snakecharm/stringLanguage/lang/psi/SmkSLSubscriptionKeyReferenceExpression.kt index 99b5cebc..97254e97 100644 --- a/src/main/kotlin/com/jetbrains/snakecharm/stringLanguage/lang/psi/SmkSLSubscriptionKeyReferenceExpression.kt +++ b/src/main/kotlin/com/jetbrains/snakecharm/stringLanguage/lang/psi/SmkSLSubscriptionKeyReferenceExpression.kt @@ -13,7 +13,7 @@ import com.jetbrains.snakecharm.lang.psi.types.SmkAvailableForSubscriptionType import com.jetbrains.snakecharm.stringLanguage.lang.SmkSLElementVisitor import com.jetbrains.snakecharm.stringLanguage.lang.parser.SmkSLTokenTypes import com.jetbrains.snakecharm.stringLanguage.lang.psi.references.SmkSLSubscriptionKeyReference - +// TODO: PySubscriptionExpression class SmkSLSubscriptionKeyReferenceExpression(node: ASTNode) : PyReferenceExpressionImpl(node), BaseSmkSLReferenceExpression { override fun getName() = referencedName diff --git a/src/test/kotlin/features/glue/OnetimeUsedSteps.kt b/src/test/kotlin/features/glue/OnetimeUsedSteps.kt new file mode 100644 index 00000000..bb3dc3aa --- /dev/null +++ b/src/test/kotlin/features/glue/OnetimeUsedSteps.kt @@ -0,0 +1,34 @@ +package features.glue + +import com.intellij.openapi.application.runReadAction +import com.jetbrains.python.psi.PyRecursiveElementVisitor +import com.jetbrains.python.psi.PyReferenceExpression +import com.jetbrains.snakecharm.stringLanguage.lang.psi.SmkSLSubscriptionKeyReferenceExpression +import io.cucumber.java.en.When + +class OnetimeUsedSteps { + @When("^validate issue 380$") + fun validateIssue380() { + runReadAction { + val psiElement = SnakemakeWorld.fixture().elementAtCaret + require(psiElement is SmkSLSubscriptionKeyReferenceExpression) { + "Actual class: ${psiElement.javaClass.simpleName}" + } + require(psiElement.text.equals("proportion")) { + "Actual text: ${psiElement.text}" + } + var counter = 0 + val visitor = object : PyRecursiveElementVisitor() { + override fun visitPyReferenceExpression(node: PyReferenceExpression) { + counter++ + node.qualifier?.accept(this) + } + } + psiElement.accept(visitor) + // Assert no SOE, i.e. stack not deep: + assert(counter < 5) { + "Actual counter: $counter" + } + } + } +} \ No newline at end of file diff --git a/src/test/resources/features/stringLanguage/issue380.feature b/src/test/resources/features/stringLanguage/issue380.feature new file mode 100644 index 00000000..0a3d863e --- /dev/null +++ b/src/test/resources/features/stringLanguage/issue380.feature @@ -0,0 +1,13 @@ +Feature: SOE, issue 380 + Scenario: Foo + Given a snakemake project + Given I open a file "foo.smk" with text + """ + def foo(): + rule: + shell: "{config[methtool][proportion]}" + pass + """ + When I put the caret after propo + Then I expect language injection on "{config[methtool][proportion]}" + And validate issue 380 \ No newline at end of file