From b236ad2f5c7b238c26e7e021d17991aaf312bc0f Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Thu, 4 Jul 2024 23:23:43 +0800 Subject: [PATCH] feat(runner): refactor ShireRunner to improve terminal task execution and error handling --- .../com/phodal/shirelang/run/ShireProgramRunner.kt | 14 ++++++++------ .../com/phodal/shirelang/run/runner/ShireRunner.kt | 8 +++++++- 2 files changed, 15 insertions(+), 7 deletions(-) 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 1f0be6bdc..25230977f 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireProgramRunner.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireProgramRunner.kt @@ -32,24 +32,26 @@ class ShireProgramRunner : GenericProgramRunner(), Disposable { val result = AtomicReference() - if(!isSubscribed) { + if (!isSubscribed) { connection.subscribe(ShireRunListener.TOPIC, object : ShireRunListener { override fun runFinish(string: String, event: ProcessEvent, scriptPath: String) { val consoleView = (environment.state as? ShireRunConfigurationProfileState)?.console environment.project.getService(ShireProcessProcessor::class.java) .process(string, event, scriptPath, consoleView) + ApplicationManager.getApplication().invokeAndWait { + val showRunContent = showRunContent( + shireState.execute(environment.executor, this@ShireProgramRunner), + environment + ) + result.set(showRunContent) + } } }) isSubscribed = true } - ApplicationManager.getApplication().invokeAndWait { - val showRunContent = showRunContent(shireState.execute(environment.executor, this), environment) - result.set(showRunContent) - } - return result.get() } diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireRunner.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireRunner.kt index 80064f7a6..0b9215ddb 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireRunner.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireRunner.kt @@ -55,7 +55,7 @@ class ShireRunner( if (runnerContext.hole?.actionLocation == ShireActionLocation.TERMINAL_MENU) { executeTerminalTask(runnerContext) { response, textRange -> - executePostFunction(runnerContext, runnerContext.hole, null, null) + executePostFunction(runnerContext, runnerContext.hole, response, textRange) } } else { executeLlmTask(runnerContext) @@ -65,6 +65,12 @@ class ShireRunner( private fun executeTerminalTask(context: ShireRunnerContext, postFunction: PostFunction) { CoroutineScope(Dispatchers.Main).launch { val handler = terminalLocationExecutor?.bundler(project, userInput) + if (handler == null) { + console.print("Terminal not found", ConsoleViewContentType.ERROR_OUTPUT) + processHandler.destroyProcess() + return@launch + } + val llmResult = StringBuilder() runBlocking { LlmProvider.provider(project)?.stream(context.finalPrompt, "", false)?.collect {