cidr workspace

This commit is contained in:
FalsePattern 2024-11-04 02:52:00 +01:00
parent 9dedbad34b
commit 3b619922b5
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
6 changed files with 130 additions and 3 deletions

View file

@ -1,11 +1,13 @@
import org.jetbrains.intellij.platform.gradle.Constants
import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType import org.jetbrains.intellij.platform.gradle.IntelliJPlatformType
val lsp4jVersion: String by project val lsp4jVersion: String by project
val clionVersion: String by project
dependencies { dependencies {
intellijPlatform { intellijPlatform {
create(IntelliJPlatformType.CLion, providers.gradleProperty("clionVersion")) create(IntelliJPlatformType.CLion, providers.gradleProperty("clionVersion"))
bundledPlugins("com.intellij.clion", "com.intellij.cidr.lang", "com.intellij.cidr.base", "com.intellij.nativeDebug") bundledPlugins("com.intellij.clion", "com.intellij.cidr.base", "com.intellij.nativeDebug")
} }
implementation(project(":core")) implementation(project(":core"))
implementation("org.eclipse.lsp4j:org.eclipse.lsp4j.debug:$lsp4jVersion") { implementation("org.eclipse.lsp4j:org.eclipse.lsp4j.debug:$lsp4jVersion") {
@ -14,3 +16,8 @@ dependencies {
exclude("com.google.code.gson", "gson") exclude("com.google.code.gson", "gson")
} }
} }
configurations[Constants.Configurations.INTELLIJ_PLATFORM_BUNDLED_PLUGINS].dependencies.configureEach {
if (this is ExternalModuleDependency) {
this.isTransitive = false
}
}

View file

@ -0,0 +1,38 @@
/*
* This file is part of ZigBrains.
*
* Copyright (C) 2023-2024 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* ZigBrains is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* ZigBrains is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.zigbrains.cidr
import com.intellij.openapi.project.Project
import com.jetbrains.cidr.project.workspace.CidrWorkspace
import com.jetbrains.cidr.project.workspace.OCRootsSynchronizer
import java.io.File
class ZigWorkspace(project: Project) : CidrWorkspace(project) {
override fun collectRootsInfo(p0: File?): OCRootsSynchronizer.RootsInfo {
return OCRootsSynchronizer.RootsInfo()
}
override fun getClientKey(): String {
return "ZIG_WORKSPACE"
}
}

View file

@ -0,0 +1,73 @@
/*
* This file is part of ZigBrains.
*
* Copyright (C) 2023-2024 FalsePattern
* All Rights Reserved
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* ZigBrains is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, only version 3 of the License.
*
* ZigBrains is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZigBrains. If not, see <https://www.gnu.org/licenses/>.
*/
package com.falsepattern.zigbrains.cidr
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.guessProjectDir
import com.intellij.openapi.vfs.toNioPathOrNull
import com.jetbrains.cidr.project.workspace.CidrWorkspace
import com.jetbrains.cidr.project.workspace.CidrWorkspaceManager
import com.jetbrains.cidr.project.workspace.CidrWorkspaceProvider
import java.io.IOException
import java.nio.file.Files
import kotlin.io.path.pathString
class ZigWorkspaceProvider: CidrWorkspaceProvider {
override fun getWorkspace(project: Project): CidrWorkspace? {
getExistingWorkspace(project)?.let { return it }
val projectDir = project.guessProjectDir()?.toNioPathOrNull() ?: return null
try {
Files.walk(projectDir).use { files ->
if (files.anyMatch { it.fileName.pathString.let { it2 -> it2.endsWith(".zig") || it2.endsWith(".zig.zon") } }) {
return ZigWorkspace(project)
}
}
} catch (e: IOException) {
e.printStackTrace()
}
return null
}
override fun loadWorkspace(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)
}
}
}
private fun getExistingWorkspace(project: Project): ZigWorkspace? {
val workspaces = CidrWorkspaceManager.getInstance(project).workspaces.keys
for (ws in workspaces)
if (ws is ZigWorkspace)
return ws
return null
}

View file

@ -0,0 +1,8 @@
<idea-plugin package="com.falsepattern.zigbrains.cidr">
<depends>com.intellij.cidr.base</depends>
<extensions defaultExtensionNs="cidr.project">
<workspaceProvider
implementation="com.falsepattern.zigbrains.cidr.ZigWorkspaceProvider"
/>
</extensions>
</idea-plugin>

View file

@ -1,5 +1,5 @@
<idea-plugin package="com.falsepattern.zigbrains.debugger"> <idea-plugin package="com.falsepattern.zigbrains.debugger">
<depends>com.intellij.modules.cidr.debugger</depends> <depends>com.intellij.nativeDebug</depends>
<extensions defaultExtensionNs="com.intellij"> <extensions defaultExtensionNs="com.intellij">
<configurationType <configurationType

View file

@ -5,7 +5,8 @@
<depends config-file="zigbrains-core.xml">com.intellij.modules.platform</depends> <depends config-file="zigbrains-core.xml">com.intellij.modules.platform</depends>
<depends config-file="zigbrains-lsp.xml">com.redhat.devtools.lsp4ij</depends> <depends config-file="zigbrains-lsp.xml">com.redhat.devtools.lsp4ij</depends>
<depends config-file="zigbrains-debugger.xml" optional="true">com.intellij.modules.cidr.debugger</depends> <depends config-file="zigbrains-debugger.xml" optional="true">com.intellij.nativeDebug</depends>
<depends config-file="zigbrains-cidr.xml" optional="true">com.intellij.cidr.base</depends>
<resource-bundle>zigbrains.Bundle</resource-bundle> <resource-bundle>zigbrains.Bundle</resource-bundle>