Skip to content

Commit

Permalink
Merge main into feature/dev-execution
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-toolkit-automation authored Jan 27, 2025
2 parents 232a273 + 65fc1a2 commit e3f7adb
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
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)
}
}
}

0 comments on commit e3f7adb

Please sign in to comment.