Skip to content

Commit 88c74f3

Browse files
committed
fix(prompts): GitBranchWorker.loadTotalDiff should not wait for built-in server on EDT
1 parent c926c2b commit 88c74f3

File tree

2 files changed

+32
-24
lines changed

2 files changed

+32
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
- Ollama icon size to 15x15.
1414
- Input is not validated when switching between clients in add and edit dialog.
15+
- GitBranchWorker.loadTotalDiff should not wait for built-in server on EDT.
1516

1617
## [2.0.0] - 2024-06-08
1718

src/main/kotlin/com/github/blarc/ai/commits/intellij/plugin/settings/prompts/PromptTable.kt

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import com.github.blarc.ai.commits.intellij.plugin.unique
1212
import com.intellij.dvcs.repo.VcsRepositoryManager
1313
import com.intellij.ide.DataManager
1414
import com.intellij.openapi.actionSystem.CommonDataKeys
15+
import com.intellij.openapi.application.ApplicationManager
16+
import com.intellij.openapi.application.ModalityState
1517
import com.intellij.openapi.ui.DialogWrapper
1618
import com.intellij.ui.components.JBTextArea
1719
import com.intellij.ui.components.JBTextField
@@ -48,11 +50,11 @@ class PromptTable {
4850
}
4951

5052
private fun createTableModel(): ListTableModel<Prompt> = ListTableModel(
51-
arrayOf(
52-
createColumn<Prompt, String>(message("settings.prompt.name")) { prompt -> prompt.name },
53-
createColumn(message("settings.prompt.description")) { prompt -> prompt.description },
54-
),
55-
prompts.values.toList()
53+
arrayOf(
54+
createColumn<Prompt, String>(message("settings.prompt.name")) { prompt -> prompt.name },
55+
createColumn(message("settings.prompt.description")) { prompt -> prompt.description },
56+
),
57+
prompts.values.toList()
5658
)
5759

5860
fun addPrompt(): Prompt? {
@@ -135,16 +137,21 @@ class PromptTable {
135137
promptPreviewTextArea.columns = 100
136138
promptPreviewTextArea.autoscrolls = false
137139

138-
DataManager.getInstance().dataContextFromFocusAsync.onSuccess {
139-
val project = it.getData(CommonDataKeys.PROJECT)
140-
val changes = VcsRepositoryManager.getInstance(project!!).repositories.stream()
140+
DataManager.getInstance().getDataContext(rootPane).getData(CommonDataKeys.PROJECT)?.let { project ->
141+
ApplicationManager.getApplication().executeOnPooledThread {
142+
143+
val changes = VcsRepositoryManager.getInstance(project).repositories.stream()
141144
.map { r -> GitBranchWorker.loadTotalDiff(r, r.currentBranchName!!) }
142145
.flatMap { r -> r.stream() }
143146
.toList()
144147

145-
branch = commonBranch(changes, project)
146-
diff = computeDiff(changes, true, project)
147-
setPreview(prompt.content, promptHintTextField.text)
148+
branch = commonBranch(changes, project)
149+
diff = computeDiff(changes, true, project)
150+
151+
ApplicationManager.getApplication().invokeLater({
152+
setPreview(prompt.content, promptHintTextField.text)
153+
}, ModalityState.stateForComponent(rootPane))
154+
}
148155
}
149156

150157
init()
@@ -153,17 +160,17 @@ class PromptTable {
153160
override fun createCenterPanel() = panel {
154161
row(message("settings.prompt.name")) {
155162
cell(promptNameTextField)
156-
.align(Align.FILL)
157-
.bindText(prompt::name)
158-
.applyIf(prompt.canBeChanged) { focused() }
159-
.validationOnApply { notBlank(it.text) }
160-
.applyIf(newPrompt == null) { validationOnApply { unique(it.text.lowercase(), prompts) } }
163+
.align(Align.FILL)
164+
.bindText(prompt::name)
165+
.applyIf(prompt.canBeChanged) { focused() }
166+
.validationOnApply { notBlank(it.text) }
167+
.applyIf(newPrompt == null) { validationOnApply { unique(it.text.lowercase(), prompts) } }
161168
}
162169
row(message("settings.prompt.description")) {
163170
cell(promptDescriptionTextField)
164-
.align(Align.FILL)
165-
.bindText(prompt::description)
166-
.validationOnApply { notBlank(it.text) }
171+
.align(Align.FILL)
172+
.bindText(prompt::description)
173+
.validationOnApply { notBlank(it.text) }
167174
}
168175
row(message("settings.prompt.hint")) {
169176
cell(promptHintTextField)
@@ -177,17 +184,17 @@ class PromptTable {
177184
}
178185
row {
179186
scrollCell(promptContentTextArea)
180-
.bindText(prompt::content)
181-
.validationOnApply { notBlank(it.text) }
182-
.onChanged { setPreview(it.text, promptHintTextField.text)}
183-
.align(Align.FILL)
187+
.bindText(prompt::content)
188+
.validationOnApply { notBlank(it.text) }
189+
.onChanged { setPreview(it.text, promptHintTextField.text) }
190+
.align(Align.FILL)
184191
}
185192
row {
186193
label("Preview")
187194
}
188195
row {
189196
scrollCell(promptPreviewTextArea)
190-
.align(Align.FILL)
197+
.align(Align.FILL)
191198
}
192199
row {
193200
comment(message("settings.prompt.comment"))

0 commit comments

Comments
 (0)