Skip to content

Commit

Permalink
Completion and resolve was implemented for 'script' section.
Browse files Browse the repository at this point in the history
Resolves: #426
  • Loading branch information
Dmitry committed Nov 25, 2021
1 parent 00b1b2b commit a2ad44c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 |
| 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 |
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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 |
| 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 |

0 comments on commit a2ad44c

Please sign in to comment.