From 474b6813565e790a832c37f74e7ac4acd6db7696 Mon Sep 17 00:00:00 2001 From: liuk Date: Fri, 6 Sep 2024 17:55:16 +0800 Subject: [PATCH] fix(runner): The consoleView is not the original consoleView when processing the exit code of the script --- .../com/phodal/shirelang/actions/ShireRunFileAction.kt | 2 +- .../kotlin/com/phodal/shirelang/run/ShireProgramRunner.kt | 5 ++--- .../shirelang/run/ShireRunConfigurationProfileState.kt | 6 +++--- .../kotlin/com/phodal/shirelang/run/ShireRunListener.kt | 3 ++- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/actions/ShireRunFileAction.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/actions/ShireRunFileAction.kt index 5fc00a2c1..db377ccd1 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/actions/ShireRunFileAction.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/actions/ShireRunFileAction.kt @@ -133,7 +133,7 @@ class ShireRunFileAction : DumbAwareAction() { val hintDisposable = Disposer.newDisposable() val connection = ApplicationManager.getApplication().messageBus.connect(hintDisposable) connection.subscribe(ShireRunListener.TOPIC, object : ShireRunListener { - override fun runFinish(allOutput: String, llmOutput: String, event: ProcessEvent, scriptPath: String) { + override fun runFinish(allOutput: String, llmOutput: String, event: ProcessEvent, scriptPath: String, consoleView: ShireConsoleView?) { future.complete(llmOutput) } }) diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireProgramRunner.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireProgramRunner.kt index 8bda78c0e..6f2b1b674 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireProgramRunner.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireProgramRunner.kt @@ -29,14 +29,13 @@ class ShireProgramRunner : GenericProgramRunner(), Disposable { if (environment.runProfile !is ShireConfiguration) return null val shireState = state as ShireRunConfigurationProfileState - var executeResult: ExecutionResult? = null + var executeResult: ExecutionResult? val result = AtomicReference() if (!isSubscribed) { connection.subscribe(ShireRunListener.TOPIC, object : ShireRunListener { - override fun runFinish(allOutput: String, llmOutput: String, event: ProcessEvent, scriptPath: String) { - val consoleView = (environment.state as? ShireRunConfigurationProfileState)?.console + override fun runFinish(allOutput: String, llmOutput: String, event: ProcessEvent, scriptPath: String, consoleView: ShireConsoleView?) { environment.project.getService(ShireProcessProcessor::class.java) .process(allOutput, event, scriptPath, consoleView) diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunConfigurationProfileState.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunConfigurationProfileState.kt index 3fd597d81..bd577825b 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunConfigurationProfileState.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunConfigurationProfileState.kt @@ -49,7 +49,7 @@ open class ShireRunConfigurationProfileState( ProcessTerminatedListener.attach(processHandler) val sb = StringBuilder() - val processAdapter = ShireProcessAdapter(sb, configuration) + val processAdapter = ShireProcessAdapter(sb, configuration, console) processHandler.addProcessListener(processAdapter) // start message log in here @@ -118,7 +118,7 @@ class ShireConsoleView(private val executionConsole: ConsoleViewImpl) : } } -class ShireProcessAdapter(private val sb: StringBuilder, val configuration: ShireConfiguration) : ProcessAdapter() { +class ShireProcessAdapter(private val sb: StringBuilder, val configuration: ShireConfiguration, val consoleView: ShireConsoleView?) : ProcessAdapter() { var result = "" private var llmOutput: String = "" @@ -127,7 +127,7 @@ class ShireProcessAdapter(private val sb: StringBuilder, val configuration: Shir ApplicationManager.getApplication().messageBus .syncPublisher(ShireRunListener.TOPIC) - .runFinish(result, llmOutput, event, configuration.getScriptPath()) + .runFinish(result, llmOutput, event, configuration.getScriptPath(), consoleView) } override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) { diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunListener.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunListener.kt index 9be449fae..627a1060d 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunListener.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunListener.kt @@ -13,8 +13,9 @@ interface ShireRunListener : EventListener { * @param llmOutput LLM output * @param event ProcessEvent * @param scriptPath script path + * @param consoleView shire consoleView */ - fun runFinish(allOutput: String, llmOutput: String, event: ProcessEvent, scriptPath: String) + fun runFinish(allOutput: String, llmOutput: String, event: ProcessEvent, scriptPath: String, consoleView: ShireConsoleView?) companion object { @Topic.AppLevel