diff --git a/base/src/META-INF/blaze-base.xml b/base/src/META-INF/blaze-base.xml
index f186817d8f7..18cddb8e893 100644
--- a/base/src/META-INF/blaze-base.xml
+++ b/base/src/META-INF/blaze-base.xml
@@ -424,6 +424,9 @@
+
diff --git a/base/src/com/google/idea/blaze/base/qsync/ProjectUpdater.java b/base/src/com/google/idea/blaze/base/qsync/ProjectUpdater.java
index a7026e015bc..ad8fd3426e8 100644
--- a/base/src/com/google/idea/blaze/base/qsync/ProjectUpdater.java
+++ b/base/src/com/google/idea/blaze/base/qsync/ProjectUpdater.java
@@ -37,7 +37,6 @@
import com.google.idea.blaze.qsync.project.ProjectPath;
import com.google.idea.blaze.qsync.project.ProjectProto;
import com.google.idea.blaze.qsync.project.ProjectProto.LibrarySource;
-import com.google.idea.common.util.Transactions;
import com.intellij.openapi.externalSystem.service.project.IdeModifiableModelsProvider;
import com.intellij.openapi.externalSystem.service.project.ProjectDataManager;
import com.intellij.openapi.module.Module;
@@ -116,7 +115,7 @@ public void onNewProjectSnapshot(Context> context, QuerySyncProjectSnapshot gr
private void updateProjectModel(ProjectProto.Project spec, Context> context) {
File imlDirectory = new File(BlazeDataStorage.getProjectDataDir(importSettings), "modules");
- Transactions.submitWriteActionTransactionAndWait(
+ ProjectUpdaterThreadingUtils.Companion.readWriteAction(
() -> {
IdeModifiableModelsProvider models =
ProjectDataManager.getInstance().createModifiableModelsProvider(project);
@@ -217,9 +216,10 @@ private void updateProjectModel(ProjectProto.Project spec, Context> context) {
.build(),
workspaceLanguageSettings);
}
- models.commit();
+
}
- });
+ return models;
+ }, models -> models.commit());
}
private Library getOrCreateLibrary(
diff --git a/base/src/com/google/idea/blaze/base/qsync/ProjectUpdaterThreadingUtils.kt b/base/src/com/google/idea/blaze/base/qsync/ProjectUpdaterThreadingUtils.kt
new file mode 100644
index 00000000000..354d2750d08
--- /dev/null
+++ b/base/src/com/google/idea/blaze/base/qsync/ProjectUpdaterThreadingUtils.kt
@@ -0,0 +1,33 @@
+package com.google.idea.blaze.base.qsync
+
+import com.google.idea.common.util.Transactions
+import com.intellij.openapi.application.readAndWriteAction
+import com.intellij.openapi.diagnostic.Logger
+import com.intellij.openapi.util.registry.Registry
+import kotlinx.coroutines.runBlocking
+import java.util.concurrent.Callable
+import java.util.function.Consumer
+
+class ProjectUpdaterThreadingUtils {
+ companion object {
+ val logger = Logger.getInstance(ProjectUpdaterThreadingUtils::class.java)
+ fun readWriteAction(readPart: Callable, commit: Consumer) {
+ if (Registry.`is`("bazel.qsync.enable.coroutine.project.updater")) {
+ runBlocking {
+ readAndWriteAction {
+ logger.info("Starting read operation")
+ val ret = readPart.call()
+ writeAction {
+ commit.accept(ret)
+ }
+ }
+ }
+ } else {
+ Transactions.submitWriteActionTransactionAndWait {
+ val ret = readPart.call()
+ commit.accept(ret)
+ }
+ }
+ }
+ }
+}
\ No newline at end of file