|
1 | 1 | package cc.unitmesh.devti.language.run
|
2 | 2 |
|
| 3 | +import cc.unitmesh.devti.language.run.flow.DevInsProcessProcessor |
| 4 | +import cc.unitmesh.devti.language.run.runner.ShireConsoleView |
| 5 | +import cc.unitmesh.devti.language.status.DevInsRunListener |
| 6 | +import cc.unitmesh.devti.util.AutoDevCoroutineScope |
| 7 | +import com.intellij.execution.ExecutionResult |
3 | 8 | import com.intellij.execution.configurations.RunProfile
|
4 | 9 | import com.intellij.execution.configurations.RunProfileState
|
5 | 10 | import com.intellij.execution.configurations.RunnerSettings
|
| 11 | +import com.intellij.execution.process.ProcessEvent |
6 | 12 | import com.intellij.execution.runners.ExecutionEnvironment
|
7 | 13 | import com.intellij.execution.runners.GenericProgramRunner
|
8 | 14 | import com.intellij.execution.runners.showRunContent
|
9 | 15 | import com.intellij.execution.ui.RunContentDescriptor
|
10 | 16 | import com.intellij.openapi.Disposable
|
11 | 17 | import com.intellij.openapi.application.ApplicationManager
|
12 | 18 | import com.intellij.openapi.fileEditor.FileDocumentManager
|
| 19 | +import kotlinx.coroutines.launch |
13 | 20 | import java.util.concurrent.atomic.AtomicReference
|
14 | 21 |
|
15 | 22 | class DevInsProgramRunner : GenericProgramRunner<RunnerSettings>(), Disposable {
|
16 | 23 | private val RUNNER_ID: String = "DevInsProgramRunner"
|
17 | 24 |
|
18 | 25 | private val connection = ApplicationManager.getApplication().messageBus.connect(this)
|
19 | 26 |
|
20 |
| -// private var isSubscribed = false |
| 27 | + private var isSubscribed = false |
21 | 28 |
|
22 | 29 | override fun getRunnerId(): String = RUNNER_ID
|
23 | 30 |
|
24 | 31 | override fun canRun(executorId: String, profile: RunProfile) = profile is DevInsConfiguration
|
25 | 32 |
|
26 | 33 | override fun doExecute(state: RunProfileState, environment: ExecutionEnvironment): RunContentDescriptor? {
|
27 | 34 | if (environment.runProfile !is DevInsConfiguration) return null
|
28 |
| - val configuration = environment.runProfile as DevInsConfiguration |
29 |
| - val devInState = state as DevInsRunConfigurationProfileState |
| 35 | + val shireState = state as DevInsRunConfigurationProfileState |
30 | 36 |
|
31 |
| - FileDocumentManager.getInstance().saveAllDocuments() |
| 37 | + var executeResult: ExecutionResult? |
32 | 38 |
|
33 | 39 | val result = AtomicReference<RunContentDescriptor>()
|
34 | 40 |
|
35 |
| -// if (!isSubscribed) { |
36 |
| -// connection.subscribe(DevInsRunListener.TOPIC, object : DevInsRunListener { |
37 |
| -// override fun runFinish(string: String, event: ProcessEvent, scriptPath: String) { |
38 |
| -// environment.project.service<DevInsProcessProcessor>().process(string, event, scriptPath) |
39 |
| -// } |
40 |
| -// }) |
41 |
| -// |
42 |
| -// isSubscribed = true |
43 |
| -// } |
44 |
| - |
45 | 41 | ApplicationManager.getApplication().invokeAndWait {
|
46 |
| - val executionResult = devInState.execute(environment.executor, this) |
47 |
| - if (configuration.showConsole) { |
48 |
| - val showRunContent = showRunContent(executionResult, environment) |
49 |
| - result.set(showRunContent) |
50 |
| - } else { |
51 |
| - result.set(null) |
| 42 | + if (!isSubscribed) { |
| 43 | + connection.subscribe(DevInsRunListener.TOPIC, object : DevInsRunListener { |
| 44 | + override fun runFinish( |
| 45 | + allOutput: String, |
| 46 | + llmOutput: String, |
| 47 | + event: ProcessEvent, |
| 48 | + scriptPath: String, |
| 49 | + consoleView: ShireConsoleView?, |
| 50 | + ) { |
| 51 | + AutoDevCoroutineScope.scope(environment.project).launch { |
| 52 | + environment.project.getService(DevInsProcessProcessor::class.java) |
| 53 | + .process(allOutput, event, scriptPath, consoleView) |
| 54 | + } |
| 55 | + } |
| 56 | + }) |
| 57 | + |
| 58 | + isSubscribed = true |
| 59 | + } |
| 60 | + |
| 61 | + executeResult = shireState.execute(environment.executor, this) |
| 62 | + |
| 63 | + if (shireState.isShowRunContent) { |
| 64 | + result.set(showRunContent(executeResult, environment)) |
52 | 65 | }
|
53 | 66 | }
|
54 | 67 |
|
|
0 commit comments