Skip to content

Commit 65fc1a2

Browse files
authored
fix(chat/inline workspace context): fix updating workspace index blocks UI thread (aws#5297)
Wrap ProjectContextProvider@updateIndex inside pluginAwareExecuteOnPooledThread to make it execute it in background context instead of EDT aws#5296
1 parent 325d1d7 commit 65fc1a2

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type" : "bugfix",
3+
"description" : "Fix UI freeze caused by updating workspace index on non background context"
4+
}

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/project/ProjectContextController.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,14 @@ import com.intellij.openapi.vfs.newvfs.BulkFileListener
1313
import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent
1414
import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent
1515
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
16+
import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
1617
import kotlinx.coroutines.CoroutineScope
1718
import kotlinx.coroutines.Job
1819
import kotlinx.coroutines.TimeoutCancellationException
1920
import kotlinx.coroutines.launch
2021
import software.aws.toolkits.core.utils.getLogger
2122
import software.aws.toolkits.core.utils.warn
23+
import software.aws.toolkits.jetbrains.utils.pluginAwareExecuteOnPooledThread
2224
import java.util.concurrent.TimeoutException
2325

2426
@Service(Service.Level.PROJECT)
@@ -38,8 +40,10 @@ class ProjectContextController(private val project: Project, private val cs: Cor
3840
val createdFiles = events.filterIsInstance<VFileCreateEvent>().mapNotNull { it.file?.path }
3941
val deletedFiles = events.filterIsInstance<VFileDeleteEvent>().map { it.file.path }
4042

41-
updateIndex(createdFiles, IndexUpdateMode.ADD)
42-
updateIndex(deletedFiles, IndexUpdateMode.REMOVE)
43+
pluginAwareExecuteOnPooledThread {
44+
updateIndex(createdFiles, IndexUpdateMode.ADD)
45+
updateIndex(deletedFiles, IndexUpdateMode.REMOVE)
46+
}
4347
}
4448
}
4549
)
@@ -68,6 +72,7 @@ class ProjectContextController(private val project: Project, private val cs: Cor
6872
emptyList()
6973
}
7074

75+
@RequiresBackgroundThread
7176
fun updateIndex(filePaths: List<String>, mode: IndexUpdateMode) {
7277
try {
7378
return projectContextProvider.updateIndex(filePaths, mode)

plugins/amazonq/shared/jetbrains-community/src/software/aws/toolkits/jetbrains/services/amazonq/project/ProjectContextEditorListener.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package software.aws.toolkits.jetbrains.services.amazonq.project
66
import com.intellij.openapi.fileEditor.FileDocumentManager
77
import com.intellij.openapi.fileEditor.FileEditorManagerEvent
88
import com.intellij.openapi.fileEditor.FileEditorManagerListener
9+
import software.aws.toolkits.jetbrains.utils.pluginAwareExecuteOnPooledThread
910

1011
class ProjectContextEditorListener : FileEditorManagerListener {
1112
override fun selectionChanged(event: FileEditorManagerEvent) {
@@ -19,6 +20,8 @@ class ProjectContextEditorListener : FileEditorManagerListener {
1920
}
2021

2122
val project = event.manager.project
22-
ProjectContextController.getInstance(project).updateIndex(listOf(oldFile.path), IndexUpdateMode.UPDATE)
23+
pluginAwareExecuteOnPooledThread {
24+
ProjectContextController.getInstance(project).updateIndex(listOf(oldFile.path), IndexUpdateMode.UPDATE)
25+
}
2326
}
2427
}

0 commit comments

Comments
 (0)