diff --git a/CHANGELOG.md b/CHANGELOG.md index da7c8d52..dd784684 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,11 @@ Changelog structure reference: ## [Unreleased] +### Fixed + +- Project + - Zig.iml file created in every project + ### Changed - Project @@ -24,6 +29,7 @@ Changelog structure reference: The configuration menu is now very similar to the intellij java toolchain management, with proper toolchain selection, detection, downloading, etc. This change will require you to re-configure your toolchains! + - Zig external library root is now no longer shown if zig is not configured ## [24.0.1] diff --git a/core/src/main/kotlin/com/falsepattern/zigbrains/project/stdlib/ZigSyntheticLibrary.kt b/core/src/main/kotlin/com/falsepattern/zigbrains/project/stdlib/ZigSyntheticLibrary.kt index 83a5df0d..558e8602 100644 --- a/core/src/main/kotlin/com/falsepattern/zigbrains/project/stdlib/ZigSyntheticLibrary.kt +++ b/core/src/main/kotlin/com/falsepattern/zigbrains/project/stdlib/ZigSyntheticLibrary.kt @@ -75,16 +75,40 @@ class ZigSyntheticLibrary(val project: Project) : SyntheticLibrary(), ItemPresen return roots } + override fun isShowInExternalLibrariesNode(): Boolean { + return !roots.isEmpty() + } + companion object { private const val ZIG_LIBRARY_ID = "Zig SDK" 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?) { - 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 root = getRoot(toolchain, project) ?: return val libRoot = LibraryRoot(root.toVirtualFileUrl(workspaceModel.getVirtualFileUrlManager()), LibraryRootTypeId.SOURCES) - val libraryTableId = LibraryTableId.ProjectLibraryTableId - val libraryId = LibraryId(ZIG_LIBRARY_ID, libraryTableId) var baseModuleDirFile: VirtualFile? = null if (project.isDirectoryBased) {