Skip to content

Commit

Permalink
Smart file path collecting. CHANGELOG was updated.
Browse files Browse the repository at this point in the history
Resolves: #277
  • Loading branch information
Dmitry committed Dec 2, 2021
1 parent 5b0c244 commit 8cf1859
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Released on ...
- TODO (see [#NNN](https://github.com/JetBrains-Research/snakecharm/issues/NNN))

### Added
- Quick fix for unresolved '.yaml' / '.yml' files (see [#277](https://github.com/JetBrains-Research/snakecharm/issues/277))
- Color Settings Page (see [#431](https://github.com/JetBrains-Research/snakecharm/issues/431))
- Inspection: highlights 'use rule' section which overrides several rules as one (see [#411](https://github.com/JetBrains-Research/snakecharm/issues/411))
- Weak warnings for unused 'log' sections in 'use rule' (see [#414](https://github.com/JetBrains-Research/snakecharm/issues/414))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ package com.jetbrains.snakecharm.inspections
import com.intellij.codeInspection.LocalQuickFix
import com.intellij.psi.*
import com.jetbrains.python.inspections.PyUnresolvedReferenceQuickFixProvider
import com.jetbrains.python.psi.PyStringLiteralExpression
import com.jetbrains.snakecharm.inspections.quickfix.CreateEnvFile
import com.jetbrains.snakecharm.lang.SnakemakeNames
import com.jetbrains.snakecharm.lang.psi.SmkFileReference
import com.jetbrains.snakecharm.lang.psi.SmkRuleOrCheckpointArgsSection

class SmkUnresolvedReferenceInspectionExtension : PyUnresolvedReferenceQuickFixProvider {
override fun registerQuickFixes(reference: PsiReference, existing: MutableList<LocalQuickFix>) {
val sec = reference.element as? SmkRuleOrCheckpointArgsSection ?: return
if (sec.sectionKeyword == SnakemakeNames.SECTION_CONDA) {
handleCondaSection(sec, existing)
val name = (sec.reference as? SmkFileReference)?.getReferencePath() ?: return
existing.add(CreateEnvFile(sec, name))
}
}

private fun handleCondaSection(st: SmkRuleOrCheckpointArgsSection, existing: MutableList<LocalQuickFix>) {
val arg = st.argumentList?.arguments
?.firstOrNull { it is PyStringLiteralExpression }
as? PyStringLiteralExpression ?: return
val name = arg.text.replace("\"", "")
existing.add(CreateEnvFile(st, name))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ open class SmkFileReference(
}

override fun getUnresolvedDescription(): String? = null

fun getReferencePath() = path
}

/**
Expand Down

0 comments on commit 8cf1859

Please sign in to comment.