feat: Hide library root if zig not configured

This commit is contained in:
FalsePattern 2025-04-11 17:47:33 +02:00
parent 270ac9e113
commit 53f4d1d330
Signed by: falsepattern
GPG key ID: E930CDEC50C50E23
2 changed files with 34 additions and 4 deletions

View file

@ -17,6 +17,11 @@ Changelog structure reference:
## [Unreleased] ## [Unreleased]
### Fixed
- Project
- Zig.iml file created in every project
### Changed ### Changed
- Project - Project
@ -24,6 +29,7 @@ Changelog structure reference:
The configuration menu is now very similar to the intellij java toolchain management, The configuration menu is now very similar to the intellij java toolchain management,
with proper toolchain selection, detection, downloading, etc. This change will require with proper toolchain selection, detection, downloading, etc. This change will require
you to re-configure your toolchains! you to re-configure your toolchains!
- Zig external library root is now no longer shown if zig is not configured
## [24.0.1] ## [24.0.1]

View file

@ -75,16 +75,40 @@ class ZigSyntheticLibrary(val project: Project) : SyntheticLibrary(), ItemPresen
return roots return roots
} }
override fun isShowInExternalLibrariesNode(): Boolean {
return !roots.isEmpty()
}
companion object { companion object {
private const val ZIG_LIBRARY_ID = "Zig SDK" private const val ZIG_LIBRARY_ID = "Zig SDK"
private const val ZIG_MODULE_ID = "ZigBrains" private const val ZIG_MODULE_ID = "ZigBrains"
private val libraryTableId = LibraryTableId.ProjectLibraryTableId
private val libraryId = LibraryId(ZIG_LIBRARY_ID, libraryTableId)
private val moduleId = ModuleId(ZIG_MODULE_ID)
suspend fun reload(project: Project, toolchain: ZigToolchain?) { suspend fun reload(project: Project, toolchain: ZigToolchain?) {
val moduleId = ModuleId(ZIG_MODULE_ID) val root = getRoot(toolchain, project)
if (root != null) {
add(project, root)
} else {
remove(project)
}
}
private suspend fun remove(project: Project) {
val workspaceModel = WorkspaceModel.getInstance(project)
workspaceModel.update("Update Zig std") { builder ->
builder.resolve(moduleId)?.let { moduleEntity ->
builder.removeEntity(moduleEntity)
}
builder.resolve(libraryId)?.let { libraryEntity ->
builder.removeEntity(libraryEntity)
}
}
}
private suspend fun add(project: Project, root: VirtualFile) {
val workspaceModel = WorkspaceModel.getInstance(project) val workspaceModel = WorkspaceModel.getInstance(project)
val root = getRoot(toolchain, project) ?: return
val libRoot = LibraryRoot(root.toVirtualFileUrl(workspaceModel.getVirtualFileUrlManager()), LibraryRootTypeId.SOURCES) val libRoot = LibraryRoot(root.toVirtualFileUrl(workspaceModel.getVirtualFileUrlManager()), LibraryRootTypeId.SOURCES)
val libraryTableId = LibraryTableId.ProjectLibraryTableId
val libraryId = LibraryId(ZIG_LIBRARY_ID, libraryTableId)
var baseModuleDirFile: VirtualFile? = null var baseModuleDirFile: VirtualFile? = null
if (project.isDirectoryBased) { if (project.isDirectoryBased) {