Skip to content

Commit

Permalink
feat(core): update InteractionType and improve coroutine handling
Browse files Browse the repository at this point in the history
Update InteractionType by removing unused ChatPanel. Improve coroutine handling in ShireCoroutineScope by using AppExecutorService. Also, refactor ShireDefaultRunner to launch
  • Loading branch information
phodal committed Jun 29, 2024
1 parent b944f93 commit fffda5c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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"),
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ShireDefaultRunner(
return@invokeLater
}

ShireCoroutineScope.scope(myProject).launch {
val llmResult = StringBuilder()
runBlocking {
LlmProvider.provider(myProject)?.stream(prompt, "", false)?.collect {
Expand All @@ -46,6 +47,7 @@ class ShireDefaultRunner(

postFunction(response)
processHandler.detachProcess()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fffda5c

Please sign in to comment.