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

Fix querysync widget for remote dev #6996

Merged
merged 2 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
}
}
}
Loading