Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type" : "bugfix",
"description" : "Fix UI freeze caused by updating workspace index on non background context"
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ import com.intellij.openapi.vfs.newvfs.BulkFileListener
import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent
import com.intellij.openapi.vfs.newvfs.events.VFileDeleteEvent
import com.intellij.openapi.vfs.newvfs.events.VFileEvent
import com.intellij.util.concurrency.annotations.RequiresBackgroundThread
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.launch
import software.aws.toolkits.core.utils.getLogger
import software.aws.toolkits.core.utils.warn
import software.aws.toolkits.jetbrains.utils.pluginAwareExecuteOnPooledThread
import java.util.concurrent.TimeoutException

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

updateIndex(createdFiles, IndexUpdateMode.ADD)
updateIndex(deletedFiles, IndexUpdateMode.REMOVE)
pluginAwareExecuteOnPooledThread {
updateIndex(createdFiles, IndexUpdateMode.ADD)
updateIndex(deletedFiles, IndexUpdateMode.REMOVE)
}
}
}
)
Expand Down Expand Up @@ -68,6 +72,7 @@ class ProjectContextController(private val project: Project, private val cs: Cor
emptyList()
}

@RequiresBackgroundThread
fun updateIndex(filePaths: List<String>, mode: IndexUpdateMode) {
try {
return projectContextProvider.updateIndex(filePaths, mode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package software.aws.toolkits.jetbrains.services.amazonq.project
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.fileEditor.FileEditorManagerEvent
import com.intellij.openapi.fileEditor.FileEditorManagerListener
import software.aws.toolkits.jetbrains.utils.pluginAwareExecuteOnPooledThread

class ProjectContextEditorListener : FileEditorManagerListener {
override fun selectionChanged(event: FileEditorManagerEvent) {
Expand All @@ -19,6 +20,8 @@ class ProjectContextEditorListener : FileEditorManagerListener {
}

val project = event.manager.project
ProjectContextController.getInstance(project).updateIndex(listOf(oldFile.path), IndexUpdateMode.UPDATE)
pluginAwareExecuteOnPooledThread {
ProjectContextController.getInstance(project).updateIndex(listOf(oldFile.path), IndexUpdateMode.UPDATE)
}
}
}
Loading