Skip to content

Commit

Permalink
Always perform a sync when building dependencies
Browse files Browse the repository at this point in the history
... and add a setting for it.

PiperOrigin-RevId: 547612002
  • Loading branch information
Googler authored and copybara-github committed Jul 12, 2023
1 parent 10de24f commit b04a183
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
22 changes: 18 additions & 4 deletions base/src/com/google/idea/blaze/base/qsync/QuerySyncProject.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.google.idea.blaze.base.model.primitives.WorkspaceRoot;
import com.google.idea.blaze.base.projectview.ProjectViewManager;
import com.google.idea.blaze.base.projectview.ProjectViewSet;
import com.google.idea.blaze.base.qsync.settings.QuerySyncSettings;
import com.google.idea.blaze.base.scope.BlazeContext;
import com.google.idea.blaze.base.settings.BlazeImportSettings;
import com.google.idea.blaze.base.sync.SyncListener;
Expand Down Expand Up @@ -140,14 +141,26 @@ public SourceToTargetMap getSourceToTargetMap() {
}

public void fullSync(BlazeContext context) {
sync(context, Optional.empty());
try {
sync(context, Optional.empty());
} catch (Exception e) {
context.handleException("Project full sync failed", e);
}
}

public void deltaSync(BlazeContext context) {
try {
syncWithCurrentSnapshot(context);
} catch (Exception e) {
context.handleException("Project delta sync failed", e);
}
}

private void syncWithCurrentSnapshot(BlazeContext context) throws Exception {
sync(context, snapshotHolder.getCurrent().map(BlazeProjectSnapshot::queryData));
}

public void sync(BlazeContext context, Optional<PostQuerySyncData> lastQuery) {
public void sync(BlazeContext context, Optional<PostQuerySyncData> lastQuery) throws Exception {
try {
SaveUtil.saveAllFiles();
BlazeProjectSnapshot newProject =
Expand All @@ -170,8 +183,6 @@ public void sync(BlazeContext context, Optional<PostQuerySyncData> lastQuery) {
SyncMode.FULL,
SyncResult.SUCCESS);
}
} catch (Exception e) {
context.handleException("Project sync failed", e);
} finally {
for (SyncListener syncListener : SyncListener.EP_NAME.getExtensions()) {
// A query sync specific callback.
Expand Down Expand Up @@ -205,6 +216,9 @@ public void enableAnalysis(BlazeContext context, PsiFile psiFile) {

public void enableAnalysis(BlazeContext context, ImmutableList<Path> workspaceRelativePaths) {
try {
if (QuerySyncSettings.getInstance().syncBeforeBuild) {
syncWithCurrentSnapshot(context);
}
context.output(
PrintOutput.output(
"Building dependencies for:\n " + Joiner.on("\n ").join(workspaceRelativePaths)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class QuerySyncConfigurable implements Configurable {

private final JPanel panel;
private final JBCheckBox displayDetailsText;
private final JBCheckBox syncBeforeBuild;

private final QuerySyncSettings settings = QuerySyncSettings.getInstance();

Expand All @@ -38,6 +39,9 @@ public QuerySyncConfigurable() {

displayDetailsText = new JBCheckBox("Display detailed dependency text in the editor");
panel.add(displayDetailsText);

syncBeforeBuild = new JBCheckBox("Sync automatically before building dependencies");
panel.add(syncBeforeBuild);
}

@Override
Expand All @@ -52,16 +56,19 @@ public QuerySyncConfigurable() {

@Override
public boolean isModified() {
return settings.showDetailedInformationInEditor != displayDetailsText.isSelected();
return settings.showDetailedInformationInEditor != displayDetailsText.isSelected()
|| settings.syncBeforeBuild != syncBeforeBuild.isSelected();
}

@Override
public void apply() throws ConfigurationException {
settings.showDetailedInformationInEditor = displayDetailsText.isSelected();
settings.syncBeforeBuild = syncBeforeBuild.isSelected();
}

@Override
public void reset() {
displayDetailsText.setSelected(settings.showDetailedInformationInEditor);
syncBeforeBuild.setSelected(settings.syncBeforeBuild);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class QuerySyncSettings implements PersistentStateComponent<QuerySyncSett
// A place holder setting, to be changed later
public boolean showDetailedInformationInEditor = true;

public boolean syncBeforeBuild = true;

public static QuerySyncSettings getInstance() {
return ApplicationManager.getApplication().getService(QuerySyncSettings.class);
}
Expand Down

0 comments on commit b04a183

Please sign in to comment.