feat: Hide library root if zig not configured
This commit is contained in:
parent
270ac9e113
commit
53f4d1d330
2 changed files with 34 additions and 4 deletions
|
@ -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]
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue