Skip to content

Commit bcd66db

Browse files
committed
fix edt blocking
1 parent bda4422 commit bcd66db

File tree

1 file changed

+16
-14
lines changed
  • plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/commands

1 file changed

+16
-14
lines changed

plugins/amazonq/chat/jetbrains-community/src/software/aws/toolkits/jetbrains/services/cwc/commands/ActionRegistrar.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
package software.aws.toolkits.jetbrains.services.cwc.commands
55

6+
import com.intellij.openapi.application.ApplicationManager
67
import com.intellij.openapi.project.Project
78
import kotlinx.coroutines.flow.MutableSharedFlow
89
import kotlinx.coroutines.flow.asSharedFlow
9-
import kotlinx.coroutines.launch
10-
import software.aws.toolkits.jetbrains.core.coroutines.projectCoroutineScope
10+
import kotlinx.coroutines.runBlocking
1111
import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.AsyncChatUiListener
1212
import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.FlareUiMessage
1313
import software.aws.toolkits.jetbrains.services.amazonq.lsp.model.aws.chat.GenericCommandParams
@@ -29,19 +29,21 @@ class ActionRegistrar {
2929
_messages.tryEmit(ContextMenuActionMessage(command, project))
3030
} else {
3131
// new agentic chat route
32-
projectCoroutineScope(project).launch {
33-
val contextExtractor = ActiveFileContextExtractor.create(fqnWebviewAdapter = null, project = project)
34-
val fileContext = contextExtractor.extractContextForTrigger(ExtractionTriggerType.ContextMenu)
35-
val codeSelection = "\n```\n${fileContext.focusAreaContext?.codeSelection?.trimIndent()?.trim()}\n```\n"
36-
var uiMessage: FlareUiMessage? = null
37-
if (command.verb != "sendToPrompt") {
38-
val params = GenericCommandParams(selection = codeSelection, triggerType = TriggerType.CONTEXT_MENU, genericCommand = command.name)
39-
uiMessage = FlareUiMessage(command = "genericCommand", params = params)
40-
} else {
41-
val params = SendToPromptParams(selection = codeSelection, triggerType = TriggerType.CONTEXT_MENU)
42-
uiMessage = FlareUiMessage(command = "sendToPrompt", params = params)
32+
ApplicationManager.getApplication().executeOnPooledThread {
33+
runBlocking {
34+
val contextExtractor = ActiveFileContextExtractor.create(fqnWebviewAdapter = null, project = project)
35+
val fileContext = contextExtractor.extractContextForTrigger(ExtractionTriggerType.ContextMenu)
36+
val codeSelection = "\n```\n${fileContext.focusAreaContext?.codeSelection?.trimIndent()?.trim()}\n```\n"
37+
var uiMessage: FlareUiMessage? = null
38+
if (command.verb != "sendToPrompt") {
39+
val params = GenericCommandParams(selection = codeSelection, triggerType = TriggerType.CONTEXT_MENU, genericCommand = command.name)
40+
uiMessage = FlareUiMessage(command = "genericCommand", params = params)
41+
} else {
42+
val params = SendToPromptParams(selection = codeSelection, triggerType = TriggerType.CONTEXT_MENU)
43+
uiMessage = FlareUiMessage(command = "sendToPrompt", params = params)
44+
}
45+
AsyncChatUiListener.notifyPartialMessageUpdate(uiMessage)
4346
}
44-
AsyncChatUiListener.notifyPartialMessageUpdate(uiMessage)
4547
}
4648
}
4749
}

0 commit comments

Comments
 (0)