Skip to content

Commit

Permalink
feat: Undeclared section threads warning should not be shown here. Cl…
Browse files Browse the repository at this point in the history
…oses #539
  • Loading branch information
iromeo committed Oct 22, 2024
1 parent 5e842e5 commit 5ee2a4e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ Released on <not released>
- [7.25.0] Support for localrule directive (see [#524](https://github.com/JetBrains-Research/snakecharm/issues/524)
- [7.11] Resource scopes support (see [#510](https://github.com/JetBrains-Research/snakecharm/issues/510)
- Inspection False Positive: Unresolved reference 'log' (see [#549](https://github.com/JetBrains-Research/snakecharm/issues/549)
-

### Fixed
- Improve parser error message when rule/module is declared with name but lacks ':' (see [#515](https://github.com/JetBrains-Research/snakecharm/issues/515))
- Support for `update` and `before_update` flags. Update inspection that warns if flag functions from `snakemake.io` is used in a wrong section, added info for all flags up to 8.23.1 version (see [#537](https://github.com/JetBrains-Research/snakecharm/issues/537))
- Inject some modules in Snakefile file resolve scope w/o import declaration, e.g. os, sys,.. (see [#553](https://github.com/JetBrains-Research/snakecharm/issues/553)
- Do not warn about unresolved `snakemake` variable in the python files, because they could be used as scripts/wrappers for snakemake rules. (see [#511](https://github.com/JetBrains-Research/snakecharm/issues/511))
- Undeclared section `threads` warning should not be shown here (see [#539](https://github.com/JetBrains-Research/snakecharm/issues/539)

### Changed
- TODO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.jetbrains.snakecharm.codeInsight.SnakemakeApiService
import com.jetbrains.snakecharm.inspections.SnakemakeInspection
import com.jetbrains.snakecharm.inspections.smksl.SmkSLUndeclaredSectionInspectionUtil.checkIsSectionNameUnresolved
import com.jetbrains.snakecharm.inspections.smksl.SmkSLUndeclaredSectionInspectionUtil.isSectionNameOfInterest
import com.jetbrains.snakecharm.lang.SnakemakeNames
import com.jetbrains.snakecharm.lang.SnakemakeNames.SNAKEMAKE_MODULE_NAME_IO
import com.jetbrains.snakecharm.lang.psi.SmkRuleOrCheckpoint
import com.jetbrains.snakecharm.stringLanguage.lang.psi.SmkSLReferenceExpression
Expand Down Expand Up @@ -53,15 +54,18 @@ object SmkSLUndeclaredSectionInspectionUtil {
fun checkIsSectionNameUnresolved(ref: PsiReference): Boolean {
val declaration = ref.resolve()

return when (declaration) {
null -> true
is PyClass -> {
return when {
(declaration == null) || (declaration is SmkRuleOrCheckpoint) -> {
// 'thread' has a default value => allow unresolved
// Undeclared sections could be not resolved (SmkSL) or resolved into enire Rule (run sections)
ref.element.text != SnakemakeNames.SECTION_THREADS
}
declaration is PyClass -> {
// is resolved to snakemake/io.py
declaration.containingFile.getQName()?.toString() == SNAKEMAKE_MODULE_NAME_IO
|| declaration.qualifiedName in SECTION_ACCESSOR_CLASSES
}

is SmkRuleOrCheckpoint -> true
else -> false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ Feature: Inspection if section isn't declared in rule
| checkpoint | run: print(version[0]) | version | [ | SmkUndeclaredSectionInspection |


Scenario Outline: No error when section name is 'threads' variable
Given a snakemake project
Given I open a file "foo.smk" with text
"""
<rule_like>:
run:
<text>
"""
And <inspection> inspection is enabled
Then I expect no inspection errors
When I check highlighting errors

# not fully implemented
Examples:
| rule_like | text | inspection |
| rule | shell("{threads}") | SmkSLUndeclaredSectionInspection |
| rule | print(threads[0]) | SmkUndeclaredSectionInspection |

Scenario Outline: No error when section name is other variable
Given a snakemake project
Given I open a file "foo.smk" with text
Expand Down

0 comments on commit 5ee2a4e

Please sign in to comment.