diff --git a/src/main/kotlin/com/jetbrains/snakecharm/lang/psi/SmkFileReference.kt b/src/main/kotlin/com/jetbrains/snakecharm/lang/psi/SmkFileReference.kt index 4350ccd4..b8058fe5 100644 --- a/src/main/kotlin/com/jetbrains/snakecharm/lang/psi/SmkFileReference.kt +++ b/src/main/kotlin/com/jetbrains/snakecharm/lang/psi/SmkFileReference.kt @@ -267,6 +267,22 @@ class SmkNotebookReference( } } +/** + * The path must built from directory with current snakefile + * version 6.5.1 + */ +class SmkScriptReference( + element: SmkArgsSection, + textRange: TextRange, + stringLiteralExpression: PyStringLiteralExpression, + path: String +) : SmkFileReference(element, textRange, stringLiteralExpression, path) { + override fun getVariants() = collectFileSystemItemLike { + val name = it.name.lowercase() + name.endsWith(".py") or name.endsWith(".r") or name.endsWith(".rmd") or name.endsWith(".jl") or name.endsWith(".rs") + } +} + /** * The path must built from directory with current snakefile * version 6.5.1 diff --git a/src/main/kotlin/com/jetbrains/snakecharm/lang/psi/impl/SmkRuleOrCheckpointArgsSectionImpl.kt b/src/main/kotlin/com/jetbrains/snakecharm/lang/psi/impl/SmkRuleOrCheckpointArgsSectionImpl.kt index 810ab067..ddb1c874 100644 --- a/src/main/kotlin/com/jetbrains/snakecharm/lang/psi/impl/SmkRuleOrCheckpointArgsSectionImpl.kt +++ b/src/main/kotlin/com/jetbrains/snakecharm/lang/psi/impl/SmkRuleOrCheckpointArgsSectionImpl.kt @@ -37,6 +37,13 @@ open class SmkRuleOrCheckpointArgsSectionImpl(node: ASTNode) : SmkArgsSectionImp stringLiteral, stringLiteral.stringValue ) } + SnakemakeNames.SECTION_SCRIPT -> getSimplePathRelatedSectionReference { stringLiteral, offsetInParent -> + SmkScriptReference( + this, + SmkPsiUtil.getReferenceRange(stringLiteral).shiftRight(offsetInParent), + stringLiteral, stringLiteral.stringValue + ) + } else -> null } diff --git a/src/test/resources/features/completion/path_in_section_completion.feature b/src/test/resources/features/completion/path_in_section_completion.feature index 1a25e88d..87c0f4ec 100644 --- a/src/test/resources/features/completion/path_in_section_completion.feature +++ b/src/test/resources/features/completion/path_in_section_completion.feature @@ -26,6 +26,11 @@ Feature: Complete file name in conda section | module | snakefile | xoo.smk | | module | snakefile | other/files/foo.smk | | module | snakefile | other/files/Snakefile | + | rule | script | xoo.py | + | rule | script | xoo.r | + | rule | script | xoo.rmd | + | rule | script | xoo.jl | + | rule | script | xoo.rs | Scenario Outline: Completion list when there are no appropriate files Given a snakemake project @@ -46,6 +51,7 @@ Feature: Complete file name in conda section | rule | conda | | checkpoint | conda | | rule | notebook | + | rule | script | Scenario Outline: Completion for file in subdirectory Given a snakemake project @@ -68,6 +74,11 @@ Feature: Complete file name in conda section | rule | conda | yaml | | checkpoint | conda | yaml | | rule | notebook | py.ipynb | + | rule | script | py | + | rule | script | r | + | rule | script | rmd | + | rule | script | jl | + | rule | script | rs | Scenario Outline: Complete in conda section for different quotes Given a snakemake project @@ -93,6 +104,9 @@ Feature: Complete file name in conda section | ' | notebook | py.ipynb | | " | notebook | py.ipynb | | """ | notebook | py.ipynb | + | ' | script | py | + | " | script | py | + | """ | script | py | Scenario Outline: Complete in conda section for fstrings in different quotes Given a snakemake project @@ -118,6 +132,9 @@ Feature: Complete file name in conda section | ' | notebook | py.ipynb | | " | notebook | py.ipynb | | """ | notebook | py.ipynb | + | ' | script | py | + | " | script | py | + | """ | script | py | Scenario Outline: Completion if rule file in subdirectory Given a snakemake project @@ -144,4 +161,7 @@ Feature: Complete file name in conda section | checkpoint | conda | envs/roo.yaml | ../envs/roo.yaml | yaml | | rule | notebook | roo.py.ipynb | ../roo.py.ipynb | py.ipynb | | rule | notebook | notebooks/roo.py.ipynb | ../notebooks/roo.py.ipynb | py.ipynb | - | rule | notebook | rules/roo.py.ipynb | roo.py.ipynb | py.ipynb | \ No newline at end of file + | rule | notebook | rules/roo.py.ipynb | roo.py.ipynb | py.ipynb | + | rule | script | roo.py | ../roo.py | py | + | rule | script | scripts/roo.py | ../scripts/roo.py | py | + | rule | script | rules/roo.py | roo.py | py | \ No newline at end of file diff --git a/src/test/resources/features/resolve/path_in_section_resolve.feature b/src/test/resources/features/resolve/path_in_section_resolve.feature index a162595a..67f378db 100644 --- a/src/test/resources/features/resolve/path_in_section_resolve.feature +++ b/src/test/resources/features/resolve/path_in_section_resolve.feature @@ -21,6 +21,11 @@ Feature: Resolve file in conda/notebook sections | rule | notebook | py.ipynb | | rule | notebook | r.ipynb | | checkpoint | notebook | py.ipynb | + | rule | script | py | + | rule | script | r | + | rule | script | rmd | + | rule | script | jl | + | rule | script | rs | Scenario Outline: Reference doesn't resolve to inappropriate file Given a snakemake project @@ -41,6 +46,11 @@ Feature: Resolve file in conda/notebook sections | rule | notebook | py.ipynb | | rule | notebook | r.ipynb | | checkpoint | notebook | py.ipynb | + | rule | script | py | + | rule | script | r | + | rule | script | rmd | + | rule | script | jl | + | rule | script | rs | Scenario Outline: Resolve to a file in a sub directory Given a snakemake project @@ -62,6 +72,11 @@ Feature: Resolve file in conda/notebook sections | rule | notebook | py.ipynb | | rule | notebook | r.ipynb | | checkpoint | notebook | py.ipynb | + | rule | script | py | + | rule | script | r | + | rule | script | rmd | + | rule | script | jl | + | rule | script | rs | Scenario Outline: Resolve for strings in different quotes Given a snakemake project @@ -84,6 +99,9 @@ Feature: Resolve file in conda/notebook sections | ' | notebook | py.ipynb | | " | notebook | py.ipynb | | """ | notebook | py.ipynb | + | ' | script | py | + | " | script | py | + | """ | script | py | Scenario Outline: Resolve is off for fstrings Given a snakemake project @@ -106,6 +124,9 @@ Feature: Resolve file in conda/notebook sections | ' | notebook | py.ipynb | | " | notebook | py.ipynb | | """ | notebook | py.ipynb | + | ' | script | py | + | " | script | py | + | """ | script | py | Scenario Outline: Resolve when string literal is divided Given a snakemake project @@ -125,6 +146,7 @@ Feature: Resolve file in conda/notebook sections | rule | conda | yaml | | checkpoint | conda | yaml | | rule | notebook | py.ipynb | + | rule | script |py | Scenario Outline: Resolve when string literal is crazily divided Given a snakemake project @@ -180,6 +202,7 @@ Feature: Resolve file in conda/notebook sections | rule | conda | yaml | | checkpoint | conda | yaml | | rule | notebook | py.ipynb | + | rule | script |py | Scenario Outline: Resolve if rule file in subdirectory Given a snakemake project @@ -202,4 +225,6 @@ Feature: Resolve file in conda/notebook sections | checkpoint | conda | envs/roo.yaml | ../envs/roo.yaml | | rule | notebook | roo.py.ipynb | ../roo.py.ipynb | | rule | notebook | notebooks/roo.py.ipynb | ../notebooks/roo.py.ipynb | - | rule | notebook | rules/roo.py.ipynb | roo.py.ipynb | \ No newline at end of file + | rule | notebook | rules/roo.py.ipynb | roo.py.ipynb | + | rule | script | scripts/roo.py | ../scripts/roo.py | + | rule | script | scripts/roo.r | ../scripts/roo.r |