@@ -5,6 +5,8 @@ import com.github.blarc.ai.commits.intellij.plugin.settings.AppSettings2
5
5
import com.github.blarc.ai.commits.intellij.plugin.wrap
6
6
import com.intellij.icons.AllIcons
7
7
import com.intellij.openapi.application.EDT
8
+ import com.intellij.openapi.application.ModalityState
9
+ import com.intellij.openapi.application.asContextElement
8
10
import com.intellij.openapi.project.Project
9
11
import com.intellij.openapi.vcs.ui.CommitMessage
10
12
import com.intellij.platform.ide.progress.withBackgroundProgress
@@ -21,7 +23,7 @@ abstract class LLMClientService<T : LLMClientConfiguration>(private val cs: Coro
21
23
abstract suspend fun buildChatModel (client : T ): ChatLanguageModel
22
24
23
25
fun generateCommitMessage (client : T , prompt : String , project : Project , commitMessage : CommitMessage ) {
24
- cs.launch(Dispatchers .Default ) {
26
+ cs.launch(Dispatchers .IO + ModalityState .current().asContextElement() ) {
25
27
withBackgroundProgress(project, message(" action.background" )) {
26
28
sendRequest(client, prompt, onSuccess = {
27
29
withContext(Dispatchers .EDT ) {
@@ -38,17 +40,18 @@ abstract class LLMClientService<T : LLMClientConfiguration>(private val cs: Coro
38
40
}
39
41
40
42
fun verifyConfiguration (client : T , label : JBLabel ) {
41
- // TODO @Blarc: Can you make this better? with notifications?
42
43
label.text = message(" settings.verify.running" )
43
- cs.launch(Dispatchers .Default ) {
44
+ cs.launch(Dispatchers .IO + ModalityState .current().asContextElement() ) {
44
45
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
+ }
48
50
}, 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
+ }
52
55
})
53
56
}
54
57
}
0 commit comments