@@ -5,6 +5,8 @@ import com.github.blarc.ai.commits.intellij.plugin.settings.AppSettings2
55import com.github.blarc.ai.commits.intellij.plugin.wrap
66import com.intellij.icons.AllIcons
77import com.intellij.openapi.application.EDT
8+ import com.intellij.openapi.application.ModalityState
9+ import com.intellij.openapi.application.asContextElement
810import com.intellij.openapi.project.Project
911import com.intellij.openapi.vcs.ui.CommitMessage
1012import com.intellij.platform.ide.progress.withBackgroundProgress
@@ -21,7 +23,7 @@ abstract class LLMClientService<T : LLMClientConfiguration>(private val cs: Coro
2123 abstract suspend fun buildChatModel (client : T ): ChatLanguageModel
2224
2325 fun generateCommitMessage (client : T , prompt : String , project : Project , commitMessage : CommitMessage ) {
24- cs.launch(Dispatchers .Default ) {
26+ cs.launch(Dispatchers .IO + ModalityState .current().asContextElement() ) {
2527 withBackgroundProgress(project, message(" action.background" )) {
2628 sendRequest(client, prompt, onSuccess = {
2729 withContext(Dispatchers .EDT ) {
@@ -38,17 +40,18 @@ abstract class LLMClientService<T : LLMClientConfiguration>(private val cs: Coro
3840 }
3941
4042 fun verifyConfiguration (client : T , label : JBLabel ) {
41- // TODO @Blarc: Can you make this better? with notifications?
4243 label.text = message(" settings.verify.running" )
43- cs.launch(Dispatchers .Default ) {
44+ cs.launch(Dispatchers .IO + ModalityState .current().asContextElement() ) {
4445 sendRequest(client, " test" , onSuccess = {
45- // This can't be called from EDT thread, because dialog blocks the EDT thread
46- label.text = message(" settings.verify.valid" )
47- label.icon = AllIcons .General .InspectionsOK
46+ withContext(Dispatchers .EDT ) {
47+ label.text = message(" settings.verify.valid" )
48+ label.icon = AllIcons .General .InspectionsOK
49+ }
4850 }, onError = {
49- // This can't be called from EDT thread, because dialog blocks the EDT thread
50- label.text = it.wrap(60 )
51- label.icon = AllIcons .General .InspectionsError
51+ withContext(Dispatchers .EDT ) {
52+ label.text = it.wrap(60 )
53+ label.icon = AllIcons .General .InspectionsError
54+ }
5255 })
5356 }
5457 }
0 commit comments