From b44bc0a7e9dc21fe2c96ea98c4466c7cf6123001 Mon Sep 17 00:00:00 2001 From: dkashyn Date: Mon, 2 Dec 2024 11:43:02 -0800 Subject: [PATCH] Use full sync if ProjectType has changed --- .../idea/blaze/base/settings/Blaze.java | 2 +- .../blaze/base/sync/BlazeSyncManager.java | 5 +---- .../base/sync/BlazeSyncStartupActivity.java | 2 +- .../sync/actions/FullSyncProjectAction.java | 2 +- .../actions/IncrementalSyncProjectAction.java | 22 +++++++++++++++---- 5 files changed, 22 insertions(+), 11 deletions(-) diff --git a/base/src/com/google/idea/blaze/base/settings/Blaze.java b/base/src/com/google/idea/blaze/base/settings/Blaze.java index d4dae4f5bc5..d6534006bc6 100644 --- a/base/src/com/google/idea/blaze/base/settings/Blaze.java +++ b/base/src/com/google/idea/blaze/base/settings/Blaze.java @@ -84,7 +84,7 @@ public static ProjectType getProjectType(@Nullable Project project) { * so we cannot reload project view from for every of such call. * This is why we have this special case to make sure that Sync respects project view selection if there is any. */ - public static ProjectType getProjectTypeBeforeSync(@Nonnull Project project) { + public static ProjectType getUpToDateProjectTypeBeforeSync(@Nonnull Project project) { BlazeImportSettingsManager blazeImportSettingsManager = BlazeImportSettingsManager.getInstance(project); if (blazeImportSettingsManager == null) { diff --git a/base/src/com/google/idea/blaze/base/sync/BlazeSyncManager.java b/base/src/com/google/idea/blaze/base/sync/BlazeSyncManager.java index 7e11dd00b48..854038b9620 100644 --- a/base/src/com/google/idea/blaze/base/sync/BlazeSyncManager.java +++ b/base/src/com/google/idea/blaze/base/sync/BlazeSyncManager.java @@ -50,13 +50,11 @@ import com.google.idea.blaze.base.settings.BlazeUserSettings.FocusBehavior; import com.google.idea.blaze.base.sync.SyncScope.SyncCanceledException; import com.google.idea.blaze.base.sync.SyncScope.SyncFailedException; -import com.google.idea.blaze.base.sync.aspects.strategy.AspectRepositoryProvider; import com.google.idea.blaze.base.sync.data.BlazeProjectDataManager; import com.google.idea.blaze.base.sync.projectview.SyncDirectoriesWarning; import com.google.idea.blaze.base.sync.status.BlazeSyncStatus; import com.google.idea.blaze.base.toolwindow.Task; import com.google.idea.blaze.base.util.SaveUtil; -import com.google.idea.blaze.base.util.TemplateWriter; import com.google.idea.blaze.common.Context; import com.google.idea.blaze.common.PrintOutput; import com.google.idea.blaze.common.PrintOutput.OutputType; @@ -69,7 +67,6 @@ import com.intellij.openapi.util.text.StringUtil; import java.util.Collection; -import java.util.Map; import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -97,7 +94,7 @@ public static void printAndLogError(String errorMessage, Context context) { /** Requests a project sync with Blaze. */ public void requestProjectSync(BlazeSyncParams syncParams) { - if (Blaze.getProjectTypeBeforeSync(project) == ProjectType.QUERY_SYNC) { + if (Blaze.getUpToDateProjectTypeBeforeSync(project) == ProjectType.QUERY_SYNC) { throw new NotSupportedWithQuerySyncException("legacy sync requested"); } if (syncParams.syncMode() == SyncMode.NO_BUILD diff --git a/base/src/com/google/idea/blaze/base/sync/BlazeSyncStartupActivity.java b/base/src/com/google/idea/blaze/base/sync/BlazeSyncStartupActivity.java index 22e3aa67e12..0f1eb98461f 100644 --- a/base/src/com/google/idea/blaze/base/sync/BlazeSyncStartupActivity.java +++ b/base/src/com/google/idea/blaze/base/sync/BlazeSyncStartupActivity.java @@ -38,7 +38,7 @@ public void runActivity(Project project) { if (importSettings == null) { return; } - if (Blaze.getProjectTypeBeforeSync(project) == ProjectType.QUERY_SYNC) { + if (Blaze.getUpToDateProjectTypeBeforeSync(project) == ProjectType.QUERY_SYNC) { // When query sync is not enabled hasProjectData triggers the load QuerySyncManager.getInstance(project) .onStartup(QuerySyncActionStatsScope.create(getClass(), null)); diff --git a/base/src/com/google/idea/blaze/base/sync/actions/FullSyncProjectAction.java b/base/src/com/google/idea/blaze/base/sync/actions/FullSyncProjectAction.java index 8a7440e6f40..67ee760d1fa 100644 --- a/base/src/com/google/idea/blaze/base/sync/actions/FullSyncProjectAction.java +++ b/base/src/com/google/idea/blaze/base/sync/actions/FullSyncProjectAction.java @@ -34,7 +34,7 @@ public class FullSyncProjectAction extends BlazeProjectSyncAction { @Override protected void runSync(Project project, AnActionEvent e) { - if (Blaze.getProjectTypeBeforeSync(project) == ProjectType.QUERY_SYNC) { + if (Blaze.getUpToDateProjectTypeBeforeSync(project) == ProjectType.QUERY_SYNC) { QuerySyncManager.getInstance(project) .fullSync(QuerySyncActionStatsScope.create(getClass(), e), TaskOrigin.USER_ACTION); } else { diff --git a/base/src/com/google/idea/blaze/base/sync/actions/IncrementalSyncProjectAction.java b/base/src/com/google/idea/blaze/base/sync/actions/IncrementalSyncProjectAction.java index 465fa303b4e..a64d2c9eafa 100644 --- a/base/src/com/google/idea/blaze/base/sync/actions/IncrementalSyncProjectAction.java +++ b/base/src/com/google/idea/blaze/base/sync/actions/IncrementalSyncProjectAction.java @@ -48,17 +48,31 @@ protected void runSync(Project project, AnActionEvent e) { } public static void doIncrementalSync(Class klass, Project project, @Nullable AnActionEvent e) { - if (Blaze.getProjectTypeBeforeSync(project) == ProjectType.QUERY_SYNC) { + // This is a project type before we refreshed project view + ProjectType currentProjectType = Blaze.getProjectType(project); + // This is a project type after we reloaded project view and actualized it in BlazeImportSettings + ProjectType refreshedProjectType = Blaze.getUpToDateProjectTypeBeforeSync(project); + boolean projectTypeChanged = currentProjectType != refreshedProjectType; + if (refreshedProjectType == ProjectType.QUERY_SYNC) { QuerySyncManager qsm = QuerySyncManager.getInstance(project); QuerySyncActionStatsScope scope = QuerySyncActionStatsScope.create(klass, e); if (!qsm.isProjectLoaded()) { qsm.onStartup(scope); } else { - qsm.deltaSync(scope, TaskOrigin.USER_ACTION); + if (projectTypeChanged) { + qsm.fullSync(scope, TaskOrigin.USER_ACTION); + } else { + qsm.deltaSync(scope, TaskOrigin.USER_ACTION); + } } } else { - BlazeSyncManager.getInstance(project) - .incrementalProjectSync(/* reason= */ "IncrementalSyncProjectAction"); + if (projectTypeChanged) { + BlazeSyncManager.getInstance(project) + .fullProjectSync(/* reason= */ "FullSyncProjectAction"); + } else { + BlazeSyncManager.getInstance(project) + .incrementalProjectSync(/* reason= */ "IncrementalSyncProjectAction"); + } } }