Skip to content

Commit

Permalink
chore: Support Jetbrains IDEs 243 - CLion (#6817)
Browse files Browse the repository at this point in the history
  • Loading branch information
LeFrosch authored Oct 3, 2024
1 parent e32a66b commit c29c248
Show file tree
Hide file tree
Showing 16 changed files with 3,629 additions and 103 deletions.
11 changes: 11 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,17 @@ http_archive(
url = CLION_242_URL,
)

CLION_243_SHA = "b2b61d44c5a501e3209577b9164d56e6148020133ce4709f79c0be3a3cd17032"

CLION_243_URL = "https://www.jetbrains.com/intellij-repository/snapshots/com/jetbrains/intellij/clion/clion/243.16718.30-EAP-SNAPSHOT/clion-243.16718.30-EAP-SNAPSHOT.zip"

http_archive(
name = "clion_2024_3",
build_file = "@//intellij_platform_sdk:BUILD.clion243",
sha256 = CLION_243_SHA,
url = CLION_243_URL,
)

DEVKIT_BUILD_FILE = """
java_import(
name = "devkit",
Expand Down
3,453 changes: 3,354 additions & 99 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions clwb/clwb.bazelproject
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ build_flags:
test_sources:
*/tests/unittests*
*/tests/integrationtests*

additional_languages:
kotlin
4 changes: 3 additions & 1 deletion clwb/sdkcompat/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ load(
"//intellij_platform_sdk:build_defs.bzl",
"select_for_plugin_api",
)
load("@rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

java_library(
kt_jvm_library(
name = "sdkcompat",
srcs = select_for_plugin_api({
"clion-2022.3": ["//clwb/sdkcompat/v223"],
Expand All @@ -26,6 +27,7 @@ java_library(
"clion-2023.3": ["//clwb/sdkcompat/v233"],
"clion-2024.1": ["//clwb/sdkcompat/v241"],
"clion-2024.2": ["//clwb/sdkcompat/v242"],
"clion-2024.3": ["//clwb/sdkcompat/v243"],
}),
visibility = ["//clwb:__pkg__"],
deps = [
Expand Down
19 changes: 19 additions & 0 deletions clwb/sdkcompat/v243/BUILD
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 = "v243",
srcs = glob(["**/*.java", "**/*.kt"]),
visibility = ["//clwb/sdkcompat:__pkg__"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2023 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.
*/

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;

// #api241
class BazelCNotificationProvider implements EditorNotificationProvider {

@Override
public @Nullable Function<? super @NotNull FileEditor, ? extends @Nullable JComponent> collectNotificationData(
@NotNull Project project, @NotNull VirtualFile virtualFile) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright 2023 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.
*/
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.convertStatus
import com.jetbrains.cidr.project.ui.isProjectAwareFile
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.*

// #api241
class CLionNotificationProvider : ProjectFixesProvider, WidgetStatusProvider, EditorNotificationWarningProvider {
override suspend fun collectFixes(project: Project, file: VirtualFile?, dataContext: DataContext): List<AnAction> {
if (file == null) {
return emptyList()
}

if (Blaze.isBlazeProject(project)) {
return emptyList()
}

if (!isProjectAwareFile(file, project) && file.fileType != BuildFileType.INSTANCE) {
return emptyList()
}
if (!BazelImportCurrentProjectAction.projectCouldBeImported(project)) {
return emptyList()
}

return listOf(ImportBazelAction(project.basePath ?: return emptyList()))
}

private class ImportBazelAction(private val root: String) : AnAction("Import Bazel project") {
override fun actionPerformed(anActionEvent: AnActionEvent) {
BazelImportCurrentProjectAction.createAction(root).run()
}
}

override fun getProjectNotification(project: Project, virtualFile: VirtualFile): ProjectNotification? {
return convertStatus(getWidgetStatus(project, virtualFile))
}

override fun getWidgetStatus(project: Project, file: VirtualFile?): WidgetStatus? {
if (Blaze.isBlazeProject(project)) {
return 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
}

if (project.basePath == null) {
return null
}

return DefaultWidgetStatus(Status.Warning, Scope.Project, "Project is not configured")
}

companion object {
private fun unregisterGenericProvider(project: Project) {
val extensionPoint = EditorNotificationProvider.EP_NAME.getPoint(project)

// Note: We need to remove the default style of showing project status and fixes used in
// Android Studio and IDEA to introduce CLion's PSW style.
for (extension in extensionPoint.extensions) {
if (extension is BazelNotificationProvider) {
extensionPoint.unregisterExtension(extension)
}
}
}

@JvmStatic
fun register(project: Project) {
unregisterGenericProvider(project)

val projectFixes = ProjectFixesProvider.Companion.EP_NAME.point
projectFixes.registerExtension(CLionNotificationProvider())

val projectNotifications = EditorNotificationWarningProvider.Companion.EP_NAME.point
projectNotifications.registerExtension(CLionNotificationProvider())

val widgetStatus = WidgetStatusProvider.Companion.EP_NAME.point
widgetStatus.registerExtension(CLionNotificationProvider())
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.google.idea.blaze.clwb;

import com.intellij.openapi.application.ApplicationManager;
import com.jetbrains.cidr.cpp.toolchains.CPPEnvironment;
import com.jetbrains.cidr.cpp.toolchains.MSVC;
import com.jetbrains.cidr.cpp.toolchains.msvc.MSVCArchAndVersion;
import com.jetbrains.cidr.cpp.toolchains.msvc.MSVCCompilerToVersionCacheService;
import java.io.File;
import javax.annotation.Nullable;

// #api232
public class MSVCCompilerVersionCompat {
public record ArchAndVersion(MSVCArchAndVersion delegate) {}

public static @Nullable ArchAndVersion getCompilerVersion(File compiler) {
final var service = ApplicationManager.getApplication()
.getService(MSVCCompilerToVersionCacheService.class);

final var result = service.getCompilerVersion(compiler.getAbsolutePath());
if (result == null) {
return null;
}

return new ArchAndVersion(result);
}

public static void setEnvironmentVersion(CPPEnvironment environment, ArchAndVersion version) {
final var msvc = (MSVC) environment.getToolSet();
msvc.setToolsVersion(version.delegate);
}
}
1 change: 1 addition & 0 deletions clwb/test_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def clwb_integration_test(name, project, srcs, deps = []):
"//intellij_platform_sdk:test_libs",
"//sdkcompat",
"@junit//jar",
"@org_opentest4j_opentest4j//jar",
],
)

Expand Down
1 change: 1 addition & 0 deletions cpp/sdkcompat/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ java_library(
"clion-2023.3": ["//cpp/sdkcompat/v233"],
"clion-2024.1": ["//cpp/sdkcompat/v241"],
"clion-2024.2": ["//cpp/sdkcompat/v242"],
"clion-2024.3": ["//cpp/sdkcompat/v243"],
}),
visibility = ["//cpp:__pkg__"],
deps = ["//intellij_platform_sdk:plugin_api"],
Expand Down
19 changes: 19 additions & 0 deletions cpp/sdkcompat/v243/BUILD
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 = "v243",
srcs = glob(["**/*.java"]),
visibility = ["//cpp/sdkcompat:__pkg__"],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright 2023 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.
*/
package com.google.idea.blaze.cpp.qsync;

import com.intellij.openapi.util.Disposer;
import com.jetbrains.cidr.lang.workspace.OCWorkspace;

/** SDK compat class for {@link OCWorkspace.ModifiableModel} */
public class OCWorkspaceModifiableModelDisposer {

private OCWorkspaceModifiableModelDisposer() {}

public static void dispose(OCWorkspace.ModifiableModel modifiableModel) {
Disposer.dispose(modifiableModel);
}
}
3 changes: 2 additions & 1 deletion intellij_platform_sdk/BUILD.clion243
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ java_import(
"plugins/clion-test-catch/lib/*.jar",
"plugins/clion-test-boost/lib/*.jar",
"plugins/nativeDebug-plugin/lib/*.jar",
"plugins/clion-ide/lib/clion-ide.jar", # For CMakeNotificationProvider
"plugins/clion-ide/lib/clion-ide.jar", # for CMakeNotificationProvider
"plugins/clion-test-google-plugin/lib/clion-test-google-plugin.jar", # for com.jetbrains.cidr.execution.testing.google
"plugins/platform-images/lib/*.jar", # for native debug plugin
]),
)

Expand Down
2 changes: 1 addition & 1 deletion intellij_platform_sdk/build_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ INDIRECT_IJ_PRODUCTS = {
"android-studio-oss-under-dev": "android-studio-2023.2",
"clion-oss-oldest-stable": "clion-2024.1",
"clion-oss-latest-stable": "clion-2024.2",
"clion-oss-under-dev": "clion-2024.2",
"clion-oss-under-dev": "clion-2024.3",
# Indirect ij_product mapping for Cloud Code Plugin OSS
"intellij-cc-oldest-stable": "intellij-2022.3",
"intellij-cc-latest-stable": "intellij-2022.3",
Expand Down
2 changes: 2 additions & 0 deletions testing/test_defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ ADD_OPENS = [
for x in [
# keep sorted
"java.base/java.io",
"java.base/java.nio",
"java.base/java.lang",
"java.base/java.util",
"java.base/java.util.concurrent",
"java.base/jdk.internal.vm",
"java.base/sun.nio.fs",
"java.desktop/java.awt",
"java.desktop/java.awt.event",
Expand Down
1 change: 0 additions & 1 deletion third_party/javascript/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ java_library(
tags = ["no-ide"],
visibility = ["//visibility:private"],
exports = select_for_plugin_api({
"clion-2024.3": ["@clion_2024_3//:angular"],
"intellij-ue-2024.3": ["@intellij_ue_2024_3//:angular"],
"intellij-ue-2022.3": ["@intellij_ue_2022_3//:angular"],
"intellij-ue-2023.1": ["@intellij_ue_2023_1//:angular"],
Expand Down

0 comments on commit c29c248

Please sign in to comment.