Skip to content

Commit

Permalink
Use full sync if ProjectType has changed
Browse files Browse the repository at this point in the history
  • Loading branch information
dkashyn-sfdc committed Dec 2, 2024
1 parent b44d89a commit b44bc0a
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 11 deletions.
2 changes: 1 addition & 1 deletion base/src/com/google/idea/blaze/base/settings/Blaze.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}

Expand Down

0 comments on commit b44bc0a

Please sign in to comment.