Skip to content

Commit

Permalink
feat(run-service): introduce new ShellRunService to support running s…
Browse files Browse the repository at this point in the history
…hell scripts. This service simplifies the execution of shell commands within the DevIns IDE, enhancing the user experience. #100
  • Loading branch information
phodal committed Mar 27, 2024
1 parent 3ce99a7 commit 44b3859
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/main/kotlin/cc/unitmesh/devti/provider/RunService.kt
Expand Up @@ -3,6 +3,7 @@ package cc.unitmesh.devti.provider
import cc.unitmesh.devti.runner.RunServiceTask
import com.intellij.execution.RunManager
import com.intellij.execution.RunnerAndConfigurationSettings
import com.intellij.execution.actions.ConfigurationContext
import com.intellij.execution.configurations.RunConfiguration
import com.intellij.execution.configurations.RunProfile
import com.intellij.openapi.diagnostic.Logger
Expand Down Expand Up @@ -35,6 +36,9 @@ interface RunService {
*/
fun createConfiguration(project: Project, virtualFile: VirtualFile): RunConfiguration? = null

fun createDefaultTestConfigurations(project: Project, element: PsiElement): RunnerAndConfigurationSettings? {
return ConfigurationContext(element).configurationsFromContext?.firstOrNull()?.configurationSettings
}
/**
* Creates a new run configuration settings for the given project and virtual file.
*
Expand Down Expand Up @@ -88,8 +92,8 @@ interface RunService {
* @param virtualFile The virtual file that represents the file to be run.
* @return The result of the run operation, or `null` if an error occurred.
*/
fun runFile(project: Project, virtualFile: VirtualFile, testElement: PsiElement?): String? {
val runTask = RunServiceTask(project, virtualFile, testElement, this)
fun runFile(project: Project, virtualFile: VirtualFile, psiElement: PsiElement?): String? {
val runTask = RunServiceTask(project, virtualFile, psiElement, this)
ProgressManager.getInstance().run(runTask)
return null
}
Expand Down
17 changes: 11 additions & 6 deletions src/main/kotlin/cc/unitmesh/devti/runner/RunServiceTask.kt
Expand Up @@ -16,6 +16,7 @@ import com.intellij.execution.testframework.sm.runner.SMTRunnerEventsListener
import com.intellij.execution.testframework.sm.runner.SMTestProxy
import com.intellij.openapi.application.invokeAndWaitIfNeeded
import com.intellij.openapi.application.runInEdt
import com.intellij.openapi.diagnostic.logger
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.Disposer
Expand Down Expand Up @@ -55,7 +56,16 @@ class RunServiceTask(
fun doRun(indicator: ProgressIndicator?): RunnerResult? {
var settings: RunnerAndConfigurationSettings? = runService.createRunSettings(project, virtualFile)
if (settings == null) {
settings = createDefaultTestConfigurations(project, testElement ?: return null) ?: return null
if (testElement == null) {
logger<RunServiceTask>().error("No run configuration found for file: ${virtualFile.path}")
return null
}
settings = runService.createDefaultTestConfigurations(project, testElement)

if (settings == null) {
logger<RunServiceTask>().error("No run configuration found for element: $testElement")
return null
}
}

settings.isActivateToolWindowBeforeRun = false
Expand Down Expand Up @@ -232,9 +242,4 @@ class RunServiceTask(
}
}
}


fun createDefaultTestConfigurations(project: Project, element: PsiElement): RunnerAndConfigurationSettings? {
return ConfigurationContext(element).configurationsFromContext?.firstOrNull()?.configurationSettings
}
}

0 comments on commit 44b3859

Please sign in to comment.