33
44package software.aws.toolkits.jetbrains.services.cwc.commands
55
6+ import com.intellij.openapi.application.ApplicationManager
67import com.intellij.openapi.project.Project
78import kotlinx.coroutines.flow.MutableSharedFlow
89import kotlinx.coroutines.flow.asSharedFlow
9- import kotlinx.coroutines.launch
10- import software.aws.toolkits.jetbrains.core.coroutines.projectCoroutineScope
10+ import kotlinx.coroutines.runBlocking
1111import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.AsyncChatUiListener
1212import software.aws.toolkits.jetbrains.services.amazonq.lsp.flareChat.FlareUiMessage
1313import 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