Skip to content

Commit baed926

Browse files
committed
fix(clients): NPE when verifying configuration
Use ModalityState to enable switching to EDT when updating text and icon. Closes #239
1 parent fc1fa8c commit baed926

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
- Rethrow generic exceptions when generating commit messages.
1313

14+
### Fixed
15+
16+
- NPE when verifying LLM client configuration.
17+
1418
## [2.2.0] - 2024-08-01
1519

1620
### Added

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/clients/LLMClientService.kt

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import com.github.blarc.ai.commits.intellij.plugin.settings.AppSettings2
55
import com.github.blarc.ai.commits.intellij.plugin.wrap
66
import com.intellij.icons.AllIcons
77
import com.intellij.openapi.application.EDT
8+
import com.intellij.openapi.application.ModalityState
9+
import com.intellij.openapi.application.asContextElement
810
import com.intellij.openapi.project.Project
911
import com.intellij.openapi.vcs.ui.CommitMessage
1012
import 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

Comments
 (0)