Skip to content

Commit

Permalink
refact: cleanup (related #536)
Browse files Browse the repository at this point in the history
  • Loading branch information
iromeo committed Oct 14, 2024
1 parent 0331223 commit dea4532
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.Service
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.ALLOWED_LAMBDA_OR_CALLABLE_ARGS
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.EXECUTION_SECTIONS_KEYWORDS
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPICompanion.RULE_OR_CHECKPOINT_ARGS_SECTION_KEYWORDS_HARDCODED
import com.jetbrains.snakecharm.framework.SmkSupportProjectSettings
Expand Down Expand Up @@ -326,12 +325,6 @@ class SnakemakeAPIService {
val RULE_OR_CHECKPOINT_ARGS_SECTION_KEYWORDS = RULE_OR_CHECKPOINT_ARGS_SECTION_KEYWORDS_HARDCODED +
SnakemakeFrameworkAPIProvider.getInstance().collectAllPossibleRuleOrCheckpointSubsectionKeywords()

val SECTION_LAMBDA_ARG_POSSIBLE_PARAMS: Set<String> =
ALLOWED_LAMBDA_OR_CALLABLE_ARGS.values.flatMap { it.asIterable() }.toMutableSet().also {
// TODO merge with deprecation provider keywords
it.addAll(RULE_OR_CHECKPOINT_ARGS_SECTION_KEYWORDS)
}

val RULE_OR_CHECKPOINT_SECTION_KEYWORDS = (RULE_OR_CHECKPOINT_ARGS_SECTION_KEYWORDS + setOf(SECTION_RUN))

val USE_SECTIONS_KEYWORDS = RULE_OR_CHECKPOINT_SECTION_KEYWORDS + SnakemakeFrameworkAPIProvider.getInstance()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ class SmkSectionVariableRequiresLambdaAccessInspection : SnakemakeInspection() {
isOnTheFly: Boolean,
session: LocalInspectionToolSession,
) = object : SnakemakeInspectionVisitor(holder, getContext(session)) {
val apiService = SnakemakeAPIService.getInstance()
val SECTION_LAMBDA_ARG_POSSIBLE_PARAMS: Set<String> =
ALLOWED_LAMBDA_OR_CALLABLE_ARGS.values.flatMap { it.asIterable() }.toSet()

override fun visitPyReferenceExpression(node: PyReferenceExpression) {
@Suppress("UnstableApiUsage")
if (node.isQualified) {
Expand All @@ -27,7 +31,11 @@ class SmkSectionVariableRequiresLambdaAccessInspection : SnakemakeInspection() {
}
@Suppress("UnstableApiUsage")
val varName = node.referencedName
if (varName == null || varName !in SnakemakeAPIService.getInstance().SECTION_LAMBDA_ARG_POSSIBLE_PARAMS) {
// Not allowed arg (e.g. wildcards, ..) and not section keyword (e.g. 'threads', 'version' etc)
if (varName == null || (
(varName !in SECTION_LAMBDA_ARG_POSSIBLE_PARAMS) &&
( varName !in apiService.RULE_OR_CHECKPOINT_ARGS_SECTION_KEYWORDS))
) {
// Not suitable case
return
}
Expand Down

0 comments on commit dea4532

Please sign in to comment.