diff --git a/core/src/main/kotlin/com/phodal/shirecore/agent/InteractionType.kt b/core/src/main/kotlin/com/phodal/shirecore/agent/InteractionType.kt index aaac67e81..ea6f5da26 100644 --- a/core/src/main/kotlin/com/phodal/shirecore/agent/InteractionType.kt +++ b/core/src/main/kotlin/com/phodal/shirecore/agent/InteractionType.kt @@ -1,7 +1,6 @@ package com.phodal.shirecore.agent enum class InteractionType(val description: String) { -// ChatPanel("Output results to the chat panel"), AppendCursor("Append content at the current cursor position"), AppendCursorStream("Append content at the current cursor position, stream output"), OutputFile("Output to a file"), @@ -13,7 +12,6 @@ enum class InteractionType(val description: String) { companion object { fun from(interaction: String): InteractionType { return when (interaction) { -// "ChatPanel" -> ChatPanel "AppendCursor" -> AppendCursor "AppendCursorStream" -> AppendCursorStream "OutputFile" -> OutputFile diff --git a/core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/FormatCodeProcessor.kt b/core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/FormatCodeProcessor.kt index 945860f10..4d50cdde5 100644 --- a/core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/FormatCodeProcessor.kt +++ b/core/src/main/kotlin/com/phodal/shirecore/middleware/builtin/FormatCodeProcessor.kt @@ -18,10 +18,10 @@ class FormatCodeProcessor : PostProcessor { override fun execute(project: Project, context: PostCodeHandleContext, console: ConsoleView?): Any { val file = context.targetFile ?: return "" - val document = PsiDocumentManager.getInstance(project).getDocument(file) - val text = document?.text ?: return "" + val document = PsiDocumentManager.getInstance(project).getDocument(file) ?: return "" val endOffset = document.textLength + /// todo: change to modify range val formattedText = CodeStyleManager.getInstance(project).reformatText(file, 0, endOffset) diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireDefaultRunner.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireDefaultRunner.kt index 72bc124e8..cf4a0784a 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireDefaultRunner.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireDefaultRunner.kt @@ -29,6 +29,7 @@ class ShireDefaultRunner( return@invokeLater } + ShireCoroutineScope.scope(myProject).launch { val llmResult = StringBuilder() runBlocking { LlmProvider.provider(myProject)?.stream(prompt, "", false)?.collect { @@ -46,6 +47,7 @@ class ShireDefaultRunner( postFunction(response) processHandler.detachProcess() + } } } } diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/utils/ShireCoroutineScope.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/utils/ShireCoroutineScope.kt index 1fbe4a8e9..aab65ff1c 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/utils/ShireCoroutineScope.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/utils/ShireCoroutineScope.kt @@ -3,12 +3,18 @@ package com.phodal.shirelang.utils import com.intellij.openapi.components.Service import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.project.Project +import com.intellij.util.concurrency.AppExecutorUtil import kotlinx.coroutines.CoroutineExceptionHandler import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.asCoroutineDispatcher + + +val workerThread = AppExecutorUtil.getAppExecutorService().asCoroutineDispatcher() + @Service(Service.Level.PROJECT) -class ShireCoroutineScope(val coroutineScope: CoroutineScope = CoroutineScope(SupervisorJob() + coroutineExceptionHandler)) { +class ShireCoroutineScope(val coroutineScope: CoroutineScope = CoroutineScope(SupervisorJob() + workerThread + coroutineExceptionHandler)) { companion object { val coroutineExceptionHandler = CoroutineExceptionHandler { _, throwable -> Logger.getInstance(ShireCoroutineScope::class.java).error(throwable)