-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
281 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
load( | ||
"//intellij_platform_sdk:build_defs.bzl", | ||
"select_for_plugin_api", | ||
) | ||
|
||
java_library( | ||
name = "sdkcompat", | ||
srcs = select_for_plugin_api({ | ||
"clion-2021.3": ["//clwb/sdkcompat/vOlder"], | ||
"clion-2022.1": ["//clwb/sdkcompat/vOlder"], | ||
"clion-2022.2": ["//clwb/sdkcompat/vOlder"], | ||
"clion-2022.3": ["//clwb/sdkcompat/vOlder"], | ||
"clion-2023.1": ["//clwb/sdkcompat/vOlder"], | ||
"clion-2023.2": ["//clwb/sdkcompat/vOlder"], | ||
"clion-2023.3": ["//clwb/sdkcompat/vOlder"], | ||
"clion-2024.1": ["//clwb/sdkcompat/vOlder"], | ||
"clion-2024.2": ["//clwb/sdkcompat/v242"], | ||
}), | ||
visibility = ["//clwb:__pkg__"], | ||
deps = [ | ||
"//base", | ||
"//intellij_platform_sdk:plugin_api", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
filegroup( | ||
name = "v242", | ||
srcs = glob(["**/*.java"]), | ||
visibility = ["//clwb/sdkcompat:__pkg__"], | ||
) |
18 changes: 18 additions & 0 deletions
18
clwb/sdkcompat/v242/com/google/idea/blaze/clwb/BazelCNotificationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.google.idea.blaze.clwb; | ||
|
||
import com.intellij.openapi.fileEditor.FileEditor; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.ui.EditorNotificationProvider; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.util.function.Function; | ||
|
||
class BazelCNotificationProvider implements EditorNotificationProvider { | ||
@Override | ||
public @Nullable Function<? super @NotNull FileEditor, ? extends @Nullable JComponent> collectNotificationData(@NotNull Project project, @NotNull VirtualFile virtualFile) { | ||
return null; | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
clwb/sdkcompat/v242/com/google/idea/blaze/clwb/CLionNotificationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
package com.google.idea.blaze.clwb; | ||
|
||
import com.google.idea.blaze.base.lang.buildfile.language.BuildFileType; | ||
import com.google.idea.blaze.base.settings.Blaze; | ||
import com.google.idea.blaze.base.wizard2.BazelImportCurrentProjectAction; | ||
import com.google.idea.blaze.base.wizard2.BazelNotificationProvider; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.DataContext; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.ui.EditorNotificationProvider; | ||
import com.jetbrains.cidr.project.ui.ProjectStatusHelperKt; | ||
import com.jetbrains.cidr.project.ui.notifications.EditorNotificationWarningProvider; | ||
import com.jetbrains.cidr.project.ui.notifications.ProjectNotification; | ||
import com.jetbrains.cidr.project.ui.popup.ProjectFixesProvider; | ||
import com.jetbrains.cidr.project.ui.widget.*; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
import static com.jetbrains.cidr.project.ui.ProjectStatusHelperKt.isProjectAwareFile; | ||
|
||
// #api242 | ||
public class CLionNotificationProvider implements ProjectFixesProvider, WidgetStatusProvider, EditorNotificationWarningProvider { | ||
private static void unregisterGenericProvider(Project project) { | ||
final var extensionPoint = EditorNotificationProvider.EP_NAME.getPoint(project); | ||
|
||
for (final var extension : extensionPoint.getExtensions()) { | ||
if (extension instanceof BazelNotificationProvider) { | ||
extensionPoint.unregisterExtension(extension); | ||
} | ||
} | ||
} | ||
|
||
public static void register(Project project) { | ||
unregisterGenericProvider(project); | ||
|
||
|
||
final var projectFixes = ProjectFixesProvider.Companion.getEP_NAME().getPoint(); | ||
projectFixes.registerExtension(new CLionNotificationProvider()); | ||
final var projectNotifications = EditorNotificationWarningProvider.Companion.getEP_NAME().getPoint(); | ||
projectNotifications.registerExtension(new CLionNotificationProvider()); | ||
final var widgetStatus = WidgetStatusProvider.Companion.getEP_NAME().getPoint(); | ||
widgetStatus.registerExtension(new CLionNotificationProvider()); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public List<AnAction> collectFixes(@NotNull Project project, @Nullable VirtualFile file, @NotNull DataContext dataContext) { | ||
if (file == null) | ||
return List.of(); | ||
|
||
if (Blaze.isBlazeProject(project)) | ||
return List.of(); | ||
|
||
if (!isProjectAwareFile(file, project) && file.getFileType() != BuildFileType.INSTANCE) { | ||
return List.of(); | ||
} | ||
if (!BazelImportCurrentProjectAction.projectCouldBeImported(project)) { | ||
return List.of(); | ||
} | ||
|
||
String root = project.getBasePath(); | ||
if (root == null) { | ||
return List.of(); | ||
} | ||
|
||
return List.of(new ImportBazelAction(root)); | ||
} | ||
|
||
private static class ImportBazelAction extends AnAction { | ||
private final String root; | ||
|
||
public ImportBazelAction(String root) { | ||
super("Import Bazel project"); | ||
this.root = root; | ||
} | ||
|
||
@Override | ||
public void actionPerformed(@NotNull AnActionEvent anActionEvent) { | ||
BazelImportCurrentProjectAction.createAction(root).run(); | ||
} | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public ProjectNotification getProjectNotification(@NotNull Project project, @NotNull VirtualFile virtualFile) { | ||
return ProjectStatusHelperKt.convertStatus(getWidgetStatus(project,virtualFile)); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public WidgetStatus getWidgetStatus(@NotNull Project project, @Nullable VirtualFile file) { | ||
|
||
if (Blaze.isBlazeProject(project)) | ||
return new DefaultWidgetStatus(Status.OK, Scope.Project, "Project is configured"); | ||
|
||
if (file == null) | ||
return null; | ||
|
||
if (!isProjectAwareFile(file, project) && file.getFileType() != BuildFileType.INSTANCE) { | ||
return null; | ||
} | ||
if (!BazelImportCurrentProjectAction.projectCouldBeImported(project)) { | ||
return null; | ||
} | ||
|
||
String root = project.getBasePath(); | ||
if (root == null) { | ||
return null; | ||
} | ||
|
||
return new DefaultWidgetStatus(Status.Warning, Scope.Project, "Project is not configured"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
filegroup( | ||
name = "vOlder", | ||
srcs = glob(["**/*.java"]), | ||
visibility = ["//clwb/sdkcompat:__pkg__"], | ||
) |
53 changes: 53 additions & 0 deletions
53
clwb/sdkcompat/vOlder/com.google.idea.blaze.clwb/BazelCNotificationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.google.idea.blaze.clwb; | ||
|
||
import com.google.idea.blaze.base.wizard2.BazelDisableImportNotification; | ||
import com.google.idea.blaze.base.wizard2.BazelImportCurrentProjectAction; | ||
import com.intellij.openapi.fileEditor.FileEditor; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.openapi.vfs.VirtualFile; | ||
import com.intellij.ui.EditorNotificationPanel; | ||
import com.intellij.ui.EditorNotificationProvider; | ||
import com.jetbrains.cidr.lang.OCFileType; | ||
import groovyjarjarantlr4.v4.runtime.misc.NotNull; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.swing.*; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Provide notification for C-family files temporarily until moving to new CLion project status | ||
* api. | ||
*/ | ||
public class BazelCNotificationProvider implements EditorNotificationProvider { | ||
|
||
@Override | ||
public @Nullable Function<? super FileEditor, ? extends JComponent> collectNotificationData( | ||
@NotNull Project project, @NotNull VirtualFile file) { | ||
if (file.getFileType() != OCFileType.INSTANCE) { | ||
return null; | ||
} | ||
|
||
if (!BazelImportCurrentProjectAction.projectCouldBeImported(project)) { | ||
return null; | ||
} | ||
if (BazelDisableImportNotification.isNotificationDisabled(project)) { | ||
return null; | ||
} | ||
|
||
String root = project.getBasePath(); | ||
if (root == null) { | ||
return null; | ||
} | ||
|
||
return fileEditor -> { | ||
EditorNotificationPanel panel = new EditorNotificationPanel(fileEditor, EditorNotificationPanel.Status.Warning); | ||
Runnable importAction = BazelImportCurrentProjectAction.createAction(root); | ||
|
||
panel.setText("Project is not configured"); | ||
panel.createActionLabel("Import Bazel project", importAction); | ||
panel.createActionLabel("Dismiss", "Bazel.DisableImportNotification"); | ||
|
||
return panel; | ||
}; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
clwb/sdkcompat/vOlder/com.google.idea.blaze.clwb/CLionNotificationProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.google.idea.blaze.clwb; | ||
|
||
import com.intellij.openapi.project.Project; | ||
|
||
// #api242 | ||
public class CLionNotificationProvider { | ||
public static void register(Project project) {} | ||
} |
Oops, something went wrong.