fix: added CIDR workspace support to make clion shut up

This commit is contained in:
FalsePattern 2024-09-27 13:31:58 +02:00
parent a9cfc17729
commit c1584a5081
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
6 changed files with 124 additions and 1 deletions

View file

@ -17,6 +17,11 @@ Changelog structure reference:
## [Unreleased]
### Fixed
- Project
- CLion will no longer prompt you to import zig projects as CMake
## [17.2.0]
### Added

View file

@ -98,7 +98,7 @@ allprojects {
dependencies {
compileOnly("org.projectlombok:lombok:1.18.32")
annotationProcessor("org.projectlombok:lombok:1.18.32")
if (path !in listOf(":", ":plugin", ":debugger")) {
if (path !in listOf(":", ":plugin", ":debugger", ":cidr")) {
intellijPlatform {
intellijIdeaCommunity(ideaVersion, useInstaller = false)
}
@ -217,6 +217,19 @@ project(":project") {
}
}
project(":cidr") {
dependencies {
implementation(project(":common"))
implementation(project(":project"))
intellijPlatform {
clion(clionVersion, useInstaller = false)
for (p in clionPlugins) {
bundledPlugin(p)
}
}
}
}
project(":debugger") {
dependencies {
implementation(project(":zig"))
@ -273,6 +286,7 @@ project(":plugin") {
implementation(project(":zig"))
implementation(project(":project"))
implementation(project(":zon"))
implementation(project(":cidr"))
implementation(project(":debugger"))
intellijPlatform {
zipSigner()

View file

@ -0,0 +1,24 @@
package com.falsepattern.zigbrains.cidr.workspace;
import com.intellij.openapi.project.Project;
import com.jetbrains.cidr.external.system.workspace.ExternalWorkspace;
import com.jetbrains.cidr.lang.toolchains.CidrToolEnvironment;
import com.jetbrains.cidr.toolchains.EnvironmentProblems;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class ZigExternalWorkspace extends ExternalWorkspace {
public ZigExternalWorkspace(@NotNull Project project) {
super(project);
}
@Override
public @Nullable CidrToolEnvironment createEnvironment(@Nullable Project project, @Nullable String s, @NotNull EnvironmentProblems environmentProblems, boolean b, @Nullable Runnable runnable) {
return null;
}
@Override
public @NotNull String getClientKey() {
return "ZIG_WORKSPACE";
}
}

View file

@ -0,0 +1,57 @@
package com.falsepattern.zigbrains.cidr.workspace;
import com.falsepattern.zigbrains.project.util.ProjectUtil;
import com.intellij.openapi.project.Project;
import com.jetbrains.cidr.project.workspace.CidrWorkspace;
import com.jetbrains.cidr.project.workspace.CidrWorkspaceManager;
import com.jetbrains.cidr.project.workspace.CidrWorkspaceProvider;
import lombok.Cleanup;
import lombok.val;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.nio.file.Files;
public class ZigWorkspaceProvider implements CidrWorkspaceProvider {
private @Nullable ZigExternalWorkspace getExistingWorkspace(@NotNull Project project) {
val workspaces = CidrWorkspaceManager.getInstance(project).getWorkspaces().keySet();
for (val ws: workspaces) {
if (ws instanceof ZigExternalWorkspace zew)
return zew;
}
return null;
}
@Override
public @Nullable CidrWorkspace getWorkspace(@NotNull Project project) {
val existingWorkspace = getExistingWorkspace(project);
if (existingWorkspace != null) {
return existingWorkspace;
}
val projectDir = ProjectUtil.guessProjectDir(project);
try {
@Cleanup val files = Files.walk(projectDir);
if (files.anyMatch(file -> file.getFileName().toString().endsWith(".zig") || file.getFileName().toString().endsWith(".zig.zon"))) {
return new ZigExternalWorkspace(project);
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
public void loadWorkspace(@NotNull Project project) {
if (getExistingWorkspace(project) != null) {
return;
}
val workspace = getWorkspace(project);
if (workspace != null) {
val manager = CidrWorkspaceManager.getInstance(project);
manager.markInitializing(workspace);
manager.markInitialized(workspace);
manager.markLoading(workspace);
manager.markLoaded(workspace);
}
}
}

View file

@ -0,0 +1,22 @@
<!--
~ Copyright 2023-2024 FalsePattern
~
~ 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.
-->
<idea-plugin package="com.falsepattern.zigbrains.cidr.workspace">
<depends>com.intellij.cidr.base</depends>
<extensions defaultExtensionNs="cidr.project">
<workspaceProvider implementation="com.falsepattern.zigbrains.cidr.workspace.ZigWorkspaceProvider"/>
</extensions>
</idea-plugin>

View file

@ -181,6 +181,7 @@ The <a href="https://github.com/Zigtools/ZLS">Zig Language Server</a>, for ZigBr
</actions>
<!-- endregion Project -->
<depends optional="true" config-file="zigbrains-zig-cidr-workspace.xml">com.intellij.cidr.base</depends>
<depends optional="true" config-file="zigbrains-zig-debugger.xml">com.intellij.modules.cidr.debugger</depends>
<depends optional="true" config-file="zigbrains-zig-clion.xml">com.intellij.modules.clion</depends>