Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reload project view, and make sure that BazelImportSettings respect p… #7088

Merged
merged 4 commits into from
Dec 3, 2024

Conversation

dkashyn-sfdc
Copy link
Contributor

@dkashyn-sfdc dkashyn-sfdc commented Nov 30, 2024

…roject view choice before performing sync calls.

Checklist

  • I have filed an issue about this change and discussed potential changes with the maintainers.
  • I have received the approval from the maintainers to make this change.
  • This is not a stylistic, refactoring, or cleanup change.

Please note that the maintainers will not be reviewing this change until all checkboxes are ticked. See
the Contributions section in the README for more
details.

Discussion thread for this change

Issue number: 7087

Description of this change

@github-actions github-actions bot added product: CLion CLion plugin product: IntelliJ IntelliJ plugin product: GoLand GoLand plugin awaiting-review Awaiting review from Bazel team on PRs labels Nov 30, 2024
@dkashyn-sfdc
Copy link
Contributor Author

Last 2 runs after git pull and it is obvious that our project will benefit from QS.
image

However, there are some gaps so "toggle" mechanism is essential.

* 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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been also looking for a way to jump between qs/as on the fly, thanks for submitting this PR! Can we add some javadoc here to reflect somthing like returns the project type with project view file lookup? and maybe make the name more matching the action it does rather than a point it code where it should be called?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 15 places where Blaze.getProjectType*(project) == ProjectType.QUERY_SYNC check is performed. So I wanted to have a special case for sync calls only. This is why name reflects this.

I don't really know how frequent the rest of places are hitting this method and saw it called from action apperance update, which cannot afford to reload file for sure.

So instead of having "get type with refresh" I'd rather keep "get type for sync and make sure the proper sync mode is used". Also we are updating BazelImportSettings here and it is ok to update those on sync but for the rest of ops I'd like to avoid this.

Copy link
Contributor Author

@dkashyn-sfdc dkashyn-sfdc Nov 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can rename it to getSelectedProjectTypeBeforeSync or so. The fact that BazelImportSetings are updated is important, yet subtle here. Before, this change it was set once during project creation, and not touched afterwards, for whatever reason.

Overall, Blaze.getProjectType*(project) == ProjectType.QUERY_SYNC is someway out of control... It is peppered over the code quite randomly, and I'm a little bit worried about it causing trouble in the future even for cases beyond sync.

Copy link
Contributor Author

@dkashyn-sfdc dkashyn-sfdc Nov 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getRefreshedProjectType or getNotCachedProjectType is another option... But then it will be a dilemma where to call those :)

@@ -61,6 +54,27 @@ public BlazeProjectData loadProject(BlazeImportSettings importSettings) {

@Override
public void saveProject(BlazeImportSettings importSettings, BlazeProjectData projectData) {
if (projectType != Blaze.getProjectType(project)) {
initBlazeProjectDataDelegate(project);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we need to call save here for the old model... But this is a thing only for Aspect one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With 50% of non-test impls not using saveProject this interface definitely needs some cleanup...

// TODO(mathewi) Tidy up the interface to remove this unnecessary stuff.

@dkashyn-sfdc dkashyn-sfdc force-pushed the dynamic-qs-enablement branch 2 times, most recently from b49a5e4 to 5bbf859 Compare November 30, 2024 15:22
@@ -48,7 +48,7 @@ protected void runSync(Project project, AnActionEvent e) {
}

public static void doIncrementalSync(Class<?> klass, Project project, @Nullable AnActionEvent e) {
if (Blaze.getProjectType(project) == ProjectType.QUERY_SYNC) {
if (Blaze.getProjectTypeBeforeSync(project) == ProjectType.QUERY_SYNC) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So when I switch from legacy sync to aspect sync, QS is able to detect it's the first sync and falls to non-incremental sync. It happens here

if (!qsm.isProjectLoaded()) {
qsm.onStartup(scope);
} else {
qsm.deltaSync(scope, TaskOrigin.USER_ACTION);


On the other hand when I switch back from QS to AS, it results in Incremental Sync which might cause some unexpected issues (For example leftoveers after QS in project model)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  private static boolean allTargetsBuild(SyncMode mode) {
    return mode == SyncMode.FULL || mode == SyncMode.INCREMENTAL;
  }

With

    } else {
      BlazeSyncManager.getInstance(project)
          .incrementalProjectSync(/* reason= */ "IncrementalSyncProjectAction");
    }
  public void incrementalProjectSync(String reason) {
    BlazeSyncParams syncParams =
        BlazeSyncParams.builder()
            .setTitle("Sync")
            .setSyncMode(SyncMode.INCREMENTAL)
            .setSyncOrigin(reason)
            .setAddProjectViewTargets(true)
            .setAddWorkingSet(BlazeUserSettings.getInstance().getExpandSyncToWorkingSet())
            .build();
    requestProjectSync(syncParams);
  }

And "Full" is:

  public void fullProjectSync(String reason) {
    BlazeSyncParams syncParams =
        BlazeSyncParams.builder()
            .setTitle("Full Sync")
            .setSyncMode(SyncMode.FULL)
            .setSyncOrigin(reason)
            .setAddProjectViewTargets(true)
            .setAddWorkingSet(BlazeUserSettings.getInstance().getExpandSyncToWorkingSet())
            .build();
    requestProjectSync(syncParams);
  }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH I've been using "INCREMENTAL" all this time and there is nothing really incremental about it :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, this means INCREMENTAL was pretty good, theoretically it should always work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but I would fall back to FULL, for sure external repo completions in starlark won't work

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After checking the code I'm not that sure about

QS is able to detect it's the first sync and falls to non-incremental sync

since nothing resets com.google.idea.blaze.base.qsync.QuerySyncManager#loadedProject for QS to do FULL or onStartup

Copy link
Contributor

@tpasternak tpasternak Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, here it ends up with calling onStartup

 if (!qsm.isProjectLoaded()) { 
   qsm.onStartup(scope); 
 } else { 
   qsm.deltaSync(scope, TaskOrigin.USER_ACTION); 

it just seems safer to me

@dkashyn-sfdc dkashyn-sfdc force-pushed the dynamic-qs-enablement branch from 33ebdc2 to d4e2597 Compare December 2, 2024 21:55
@dkashyn-sfdc dkashyn-sfdc force-pushed the dynamic-qs-enablement branch from d4e2597 to b44bc0a Compare December 2, 2024 21:56
@tpasternak tpasternak merged commit 8581c5f into bazelbuild:master Dec 3, 2024
5 checks passed
@github-actions github-actions bot removed the awaiting-review Awaiting review from Bazel team on PRs label Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product: CLion CLion plugin product: GoLand GoLand plugin product: IntelliJ IntelliJ plugin
Projects
Development

Successfully merging this pull request may close these issues.

4 participants