Skip to content

Commit

Permalink
refact: rename method and classes
Browse files Browse the repository at this point in the history
  • Loading branch information
iromeo committed Oct 18, 2024
1 parent 45944f0 commit c994cd0
Show file tree
Hide file tree
Showing 55 changed files with 283 additions and 298 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import com.intellij.psi.impl.source.PostprocessReformattingAspect
import com.intellij.psi.util.PsiTreeUtil
import com.jetbrains.python.codeInsight.editorActions.moveUpDown.PyStatementMover
import com.jetbrains.python.psi.*
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.TOPLEVEL_ARGS_SECTION_KEYWORDS
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPIProjectService
import com.jetbrains.snakecharm.codeInsight.SnakemakeApi
import com.jetbrains.snakecharm.codeInsight.SnakemakeApi.TOPLEVEL_ARGS_SECTION_KEYWORDS
import com.jetbrains.snakecharm.codeInsight.SnakemakeApiService
import com.jetbrains.snakecharm.lang.psi.*

open class SmkStatementMover : PyStatementMover() {
Expand Down Expand Up @@ -73,7 +73,7 @@ open class SmkStatementMover : PyStatementMover() {
elementToMove: PsiElement,
down: Boolean
): LineRange? {
val api = SnakemakeAPIProjectService.getInstance(elementToMove.project)
val api = SnakemakeApiService.getInstance(elementToMove.project)

val document = file.viewProvider.document ?: return null
val offset = if (down) elementToMove.textRange.endOffset else elementToMove.textRange.startOffset
Expand Down Expand Up @@ -129,20 +129,20 @@ open class SmkStatementMover : PyStatementMover() {
private fun isNotAvailableForMoveInto(
elementToMove: PsiElement,
destination: PsiElement?,
api: SnakemakeAPIProjectService
api: SnakemakeApiService
): Boolean {
return (elementToMove is SmkSection && elementToMove !is SmkRunSection &&
((destination is SmkRuleOrCheckpoint &&
elementToMove.sectionKeyword !in api.getRuleOrCheckpointArgsSectionKeywords()) ||
(destination is SmkSubworkflow &&
elementToMove.sectionKeyword !in SnakemakeAPI.SUBWORKFLOW_SECTIONS_KEYWORDS) ||
elementToMove.sectionKeyword !in SnakemakeApi.SUBWORKFLOW_SECTIONS_KEYWORDS) ||
(destination is SmkModule &&
elementToMove.sectionKeyword !in api.getModuleSectionKeywords()) ||
(destination is SmkUse &&
elementToMove.sectionKeyword !in api.getUseSectionKeywords())))
}

private fun isAvailableForMoveOut(elementToMove: PsiElement, down: Boolean, api: SnakemakeAPIProjectService): Boolean {
private fun isAvailableForMoveOut(elementToMove: PsiElement, down: Boolean, api: SnakemakeApiService): Boolean {
val useSectionsKeywords = api.getUseSectionKeywords()

val statementList = getStatementList(elementToMove) ?: return true
Expand Down Expand Up @@ -234,7 +234,7 @@ open class SmkStatementMover : PyStatementMover() {
/**
* modified version
*/
private fun moveOut(elementToMove: PsiElement, editor: Editor, down: Boolean, api: SnakemakeAPIProjectService): ScopeRange? {
private fun moveOut(elementToMove: PsiElement, editor: Editor, down: Boolean, api: SnakemakeApiService): ScopeRange? {
val statementList = getStatementList(elementToMove) ?: return null
val statements = statementList.statements

Expand Down Expand Up @@ -281,7 +281,7 @@ open class SmkStatementMover : PyStatementMover() {
down: Boolean,
statements: Array<PyStatement>,
clazz: Class<T>,
api: SnakemakeAPIProjectService
api: SnakemakeApiService
): ScopeRange? {
val useSectionsKeywords = api.getUseSectionKeywords()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import com.jetbrains.python.psi.resolve.fromSdk
import com.jetbrains.python.psi.resolve.resolveQualifiedName
import com.jetbrains.python.psi.types.TypeEvalContext
import com.jetbrains.snakecharm.SnakemakeBundle
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.SECTION_ACCESSOR_CLASSES
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.SMK_API_VERS_6_1
import com.jetbrains.snakecharm.codeInsight.SnakemakeApi.SECTION_ACCESSOR_CLASSES
import com.jetbrains.snakecharm.codeInsight.SnakemakeApi.SMK_API_VERS_6_1
import com.jetbrains.snakecharm.codeInsight.completion.SmkCompletionUtil
import com.jetbrains.snakecharm.framework.SmkSupportProjectSettings
import com.jetbrains.snakecharm.framework.SmkSupportProjectSettingsListener
Expand All @@ -44,7 +44,7 @@ import javax.swing.SwingUtilities
* @date 2019-05-07
*/
@Suppress("UnstableApiUsage")
class ImplicitPySymbolsProvider(
class SmkImplicitPySymbolsProvider(
val project: Project,
) : Disposable {

Expand Down Expand Up @@ -232,11 +232,11 @@ class ImplicitPySymbolsProvider(

val packages = PythonPackageManager.forSdk(project, sdk).installedPackages

val pkgSnakemake = packages.firstOrNull { it.name == SnakemakeAPI.SMK_API_PKG_NAME_SMK }
val pkgSnakemake = packages.firstOrNull { it.name == SnakemakeApi.SMK_API_PKG_NAME_SMK }
if (pkgSnakemake != null) {
return PyPackage(pkgSnakemake.name, pkgSnakemake.version).matches(requirementSnakemake)
}
val pkgSnakemakeMinimal = packages.firstOrNull { it.name == SnakemakeAPI.SMK_API_PKG_NAME_SMK_MINIMAL }
val pkgSnakemakeMinimal = packages.firstOrNull { it.name == SnakemakeApi.SMK_API_PKG_NAME_SMK_MINIMAL }
if (pkgSnakemakeMinimal != null) {
return PyPackage(pkgSnakemakeMinimal.name, pkgSnakemakeMinimal.version).matches(requirementSnakemakeMinimal)
}
Expand Down Expand Up @@ -648,11 +648,11 @@ class ImplicitPySymbolsProvider(
usedFiles.add(commonFile.virtualFile)
}

globals[SnakemakeAPI.SMK_VARS_CHECKPOINTS] = commonFile?.findTopLevelClass("Checkpoints")
globals[SnakemakeAPI.SMK_VARS_RULES] = commonFile?.findTopLevelClass("Rules")
globals[SnakemakeAPI.SMK_VARS_SCATTER] = commonFile?.findTopLevelClass("Scatter")
globals[SnakemakeAPI.SMK_VARS_GATHER] = commonFile?.findTopLevelClass("Gather")
globals[SnakemakeAPI.SMK_VARS_CONFIG] = null
globals[SnakemakeApi.SMK_VARS_CHECKPOINTS] = commonFile?.findTopLevelClass("Checkpoints")
globals[SnakemakeApi.SMK_VARS_RULES] = commonFile?.findTopLevelClass("Rules")
globals[SnakemakeApi.SMK_VARS_SCATTER] = commonFile?.findTopLevelClass("Scatter")
globals[SnakemakeApi.SMK_VARS_GATHER] = commonFile?.findTopLevelClass("Gather")
globals[SnakemakeApi.SMK_VARS_CONFIG] = null

val checkpointsFile = collectPyFiles("snakemake.checkpoints", usedFiles, sdk).firstOrNull()
if (checkpointsFile != null) {
Expand Down Expand Up @@ -684,7 +684,7 @@ class ImplicitPySymbolsProvider(

elementsCache.add(
SmkCodeInsightScope.TOP_LEVEL to SmkCompletionUtil.createPrioritizedLookupElement(
SnakemakeAPI.SMK_VARS_PEP,
SnakemakeApi.SMK_VARS_PEP,
pepObjectConstructor,
typeText = SnakemakeBundle.message("TYPES.rule.run.workflow.globals.type.text"),
priority = SmkCompletionUtil.WORKFLOW_GLOBALS_PRIORITY
Expand All @@ -693,8 +693,8 @@ class ImplicitPySymbolsProvider(
}

companion object {
private val LOG = logger<ImplicitPySymbolsProvider>() // TODO: cleanup
fun instance(project: Project) = project.service<ImplicitPySymbolsProvider>()
private val LOG = logger<SmkImplicitPySymbolsProvider>() // TODO: cleanup
fun instance(project: Project) = project.service<SmkImplicitPySymbolsProvider>()
}

override fun dispose() {
Expand Down Expand Up @@ -727,7 +727,7 @@ private class ImplicitPySymbolsCacheImpl(
private fun validElements(elements: List<ImplicitPySymbol>): List<ImplicitPySymbol> {
val validElements = elements.filter { it.psiDeclaration.isValid }
if (validElements.size != elements.size) {
project.service<ImplicitPySymbolsProvider>().scheduleUpdate()
project.service<SmkImplicitPySymbolsProvider>().scheduleUpdate()
}
return validElements
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import com.jetbrains.python.psi.resolve.resolveQualifiedName
import com.jetbrains.python.psi.types.PyType
import com.jetbrains.python.psi.types.PyTypeProviderBase
import com.jetbrains.python.psi.types.TypeEvalContext
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.SECTION_ACCESSOR_CLASSES
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.SMK_VARS_CHECKPOINTS
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.SMK_VARS_PEP
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.SMK_VARS_RULES
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.SMK_VARS_WILDCARDS
import com.jetbrains.snakecharm.codeInsight.SnakemakeAPI.WILDCARDS_ACCESSOR_CLASS
import com.jetbrains.snakecharm.codeInsight.SnakemakeApi.SECTION_ACCESSOR_CLASSES
import com.jetbrains.snakecharm.codeInsight.SnakemakeApi.SMK_VARS_CHECKPOINTS
import com.jetbrains.snakecharm.codeInsight.SnakemakeApi.SMK_VARS_PEP
import com.jetbrains.snakecharm.codeInsight.SnakemakeApi.SMK_VARS_RULES
import com.jetbrains.snakecharm.codeInsight.SnakemakeApi.SMK_VARS_WILDCARDS
import com.jetbrains.snakecharm.codeInsight.SnakemakeApi.WILDCARDS_ACCESSOR_CLASS
import com.jetbrains.snakecharm.framework.SmkSupportProjectSettings
import com.jetbrains.snakecharm.lang.SnakemakeLanguageDialect
import com.jetbrains.snakecharm.lang.psi.*
Expand Down Expand Up @@ -110,7 +110,7 @@ class SmkTypeProvider : PyTypeProviderBase() {
lambda, SmkRuleOrCheckpointArgsSection::class.java, PyCallExpression::class.java
) ?: return null

val apiService = SnakemakeAPIProjectService.getInstance(lambda.project)
val apiService = SnakemakeApiService.getInstance(lambda.project)
val allowedArgs = apiService.getLambdaArgsForSubsection(
parentSection.sectionKeyword, ruleLike.sectionKeyword
)
Expand Down
Loading

0 comments on commit c994cd0

Please sign in to comment.