Skip to content

Commit

Permalink
Fix querysync widget for remote dev (#6996)
Browse files Browse the repository at this point in the history
* Fix querysync widget for remote dev

* Fix
  • Loading branch information
agluszak authored Nov 14, 2024
1 parent b3cb634 commit 2bbe4de
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 3 deletions.
6 changes: 4 additions & 2 deletions base/src/META-INF/blaze-base.xml
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,10 @@
<applicationService serviceImplementation="com.google.idea.blaze.base.qsync.settings.QuerySyncSettings" id="QuerySyncSettings"/>
<psi.referenceContributor language="BUILD" implementation="com.google.idea.blaze.base.lang.buildfile.references.VisibilityReferenceContributor"/>
<projectService serviceImplementation="com.google.idea.blaze.base.qsync.QuerySyncManager"/>
<iw.actionProvider implementation="com.google.idea.blaze.base.qsync.QuerySyncInspectionWidgetActionProvider"/>
<iw.actionProvider implementation="com.google.idea.blaze.base.qsync.ComposePreviewQuerySyncInspectionWidgetActionProvider"/>
<editorNotificationProvider implementation="com.google.idea.blaze.base.qsync.QuerySyncNotificationProvider"/>
<!-- Disabled until a fix is introduced in the platform to make InspectionWidgetActionProvider work with remote dev -->
<!-- <iw.actionProvider implementation="com.google.idea.blaze.base.qsync.QuerySyncInspectionWidgetActionProvider"/>-->
<!-- <iw.actionProvider implementation="com.google.idea.blaze.base.qsync.ComposePreviewQuerySyncInspectionWidgetActionProvider"/>-->
<daemon.highlightInfoFilter implementation="com.google.idea.blaze.base.qsync.QuerySyncHighlightingFilter"/>
<trafficLightRendererContributor implementation="com.google.idea.blaze.base.qsync.QuerySyncTrafficLightRendererContributor"/>
<editorNotificationProvider implementation="com.google.idea.blaze.base.qsync.UnsyncedFileEditorNotificationProvider" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public AnAction createAction(@NotNull Editor editor) {
return new BuildDependencies(editor);
}

private static class BuildDependencies extends AnAction
public static class BuildDependencies extends AnAction
implements CustomComponentAction, DumbAware {

private final Editor editor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
* Copyright 2022 The Bazel Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
package com.google.idea.blaze.base.qsync;

import com.google.idea.blaze.base.qsync.QuerySyncManager.OperationType;
import com.google.idea.blaze.base.qsync.action.BuildDependenciesHelper;
import com.google.idea.blaze.base.qsync.action.BuildDependenciesHelper.DepsBuildType;
import com.google.idea.blaze.base.qsync.settings.QuerySyncSettings;
import com.google.idea.blaze.base.settings.Blaze;
import com.google.idea.blaze.base.settings.BlazeImportSettings.ProjectType;
import com.google.idea.blaze.qsync.project.TargetsToBuild;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.TextEditor;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.EditorNotificationPanel;
import com.intellij.ui.EditorNotificationProvider;
import com.intellij.ui.EditorNotifications;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.util.Optional;
import java.util.function.Function;

/**
* Provides a custom notification at the top of file editors to build dependencies and enable analysis.
*/
public class QuerySyncNotificationProvider implements EditorNotificationProvider, DumbAware {

@Override
@Nullable
public Function<? super FileEditor, ? extends JComponent> collectNotificationData(@NotNull Project project, @NotNull VirtualFile file) {

return fileEditor -> {
if (Blaze.getProjectType(project) != ProjectType.QUERY_SYNC) {
return null;
}

if (!(fileEditor instanceof TextEditor)) {
return null;
}

BuildDependenciesHelper buildDepsHelper = new BuildDependenciesHelper(project, QuerySyncInspectionWidgetActionProvider.BuildDependencies.class, DepsBuildType.SELF);
TargetsToBuild toBuild = buildDepsHelper.getTargetsToEnableAnalysisFor(file);

if (toBuild.isEmpty()) {
return null;
}

Optional<OperationType> currentOperation = QuerySyncManager.getInstance(project).currentOperation();

if (currentOperation.isPresent()) {
return null;
}

if (toBuild.type() != TargetsToBuild.Type.SOURCE_FILE) {
return null;
}

int missing = buildDepsHelper.getSourceFileMissingDepsCount(toBuild);
if (missing > 0) {
String dependency = StringUtil.pluralize("dependency", missing);
String notificationText = String.format("Analysis disabled - missing %d %s ", missing, dependency);
return new QuerySyncNotificationPanel(fileEditor, project, notificationText);
} else {
return null;
}
};
}

private class QuerySyncNotificationPanel extends EditorNotificationPanel {

QuerySyncNotificationPanel(FileEditor editor, Project project, String notificationText) {
super(editor, Status.Warning);

setText(notificationText);

String actionId = "Blaze.BuildDependencies";
createActionLabel("Build dependencies", () -> executeAction(actionId))
.addHyperlinkListener(event -> EditorNotifications.getInstance(project).updateAllNotifications());
}
}
}

0 comments on commit 2bbe4de

Please sign in to comment.