generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(runner): add ShireFileRunService and enhance run configuration
#165 - Implement ShireFileRunService for handling file execution. - Update ShireRunConfigurationProfileState to support data context loading. - Minor fixes and improvements in related classes.
- Loading branch information
Showing
4 changed files
with
105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
shirelang/src/main/kotlin/com/phodal/shirelang/runner/ShireFileRunService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.phodal.shirelang.runner | ||
|
||
import com.intellij.execution.RunManager | ||
import com.intellij.execution.RunnerAndConfigurationSettings | ||
import com.intellij.execution.configurations.RunConfiguration | ||
import com.intellij.execution.configurations.RunProfile | ||
import com.intellij.openapi.actionSystem.impl.SimpleDataContext | ||
import com.intellij.openapi.application.runReadAction | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.vfs.VirtualFile | ||
import com.intellij.psi.PsiElement | ||
import com.intellij.psi.PsiManager | ||
import com.intellij.testFramework.LightVirtualFile | ||
import com.phodal.shirecore.provider.shire.FileRunService | ||
import com.phodal.shirelang.psi.ShireFile | ||
import com.phodal.shirelang.run.ShireConfiguration | ||
import com.phodal.shirelang.run.ShireConfigurationType | ||
import com.phodal.shirelang.run.ShireRunConfigurationProfileState | ||
|
||
class ShireFileRunService : FileRunService { | ||
override fun isApplicable(project: Project, file: VirtualFile): Boolean { | ||
return PsiManager.getInstance(project).findFile(file) is ShireFile | ||
} | ||
|
||
override fun runConfigurationClass(project: Project): Class<out RunProfile> = ShireConfiguration::class.java | ||
|
||
override fun createConfiguration(project: Project, virtualFile: VirtualFile): RunConfiguration? { | ||
val configurationSetting = runReadAction { | ||
val psiFile = | ||
PsiManager.getInstance(project).findFile(virtualFile) as? ShireFile ?: return@runReadAction null | ||
RunManager.getInstance(project) | ||
.createConfiguration(psiFile.name, ShireConfigurationType.getInstance()) | ||
} ?: return null | ||
|
||
val shireConfiguration = configurationSetting.configuration as ShireConfiguration | ||
shireConfiguration.name = virtualFile.nameWithoutExtension | ||
shireConfiguration.setScriptPath(virtualFile.path) | ||
|
||
return shireConfiguration | ||
} | ||
|
||
override fun createRunSettings( | ||
project: Project, | ||
virtualFile: VirtualFile, | ||
testElement: PsiElement?, | ||
): RunnerAndConfigurationSettings? { | ||
val runManager = RunManager.getInstance(project) | ||
|
||
val psiFile = runReadAction { | ||
PsiManager.getInstance(project).findFile(virtualFile) as? ShireFile ?: return@runReadAction null | ||
} ?: return null | ||
|
||
val setting = runReadAction { | ||
runManager.createConfiguration(psiFile.name, ShireConfigurationType.getInstance()) | ||
} | ||
|
||
val shireConfiguration = setting.configuration as ShireConfiguration | ||
shireConfiguration.name = virtualFile.nameWithoutExtension | ||
|
||
if (virtualFile is LightVirtualFile) { | ||
val dataContext = SimpleDataContext.builder() | ||
.add<ShireFile>(ShireRunConfigurationProfileState.SHIRE_VIRTUAL_KEY, psiFile).build() | ||
|
||
} | ||
|
||
shireConfiguration.setScriptPath(virtualFile.path) | ||
|
||
runManager.setTemporaryConfiguration(setting) | ||
|
||
setting.isTemporary = true | ||
runManager.selectedConfiguration = setting | ||
|
||
return setting | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters