Skip to content

Commit

Permalink
fix: Suggested fix for #380
Browse files Browse the repository at this point in the history
  • Loading branch information
iromeo committed Jul 15, 2021
1 parent 6f2e66a commit 32fd378
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 34 additions & 0 deletions src/test/kotlin/features/glue/OnetimeUsedSteps.kt
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
13 changes: 13 additions & 0 deletions src/test/resources/features/stringLanguage/issue380.feature
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 32fd378

Please sign in to comment.