fix: zig env IDE error
This commit is contained in:
parent
f26be52940
commit
6b8b82e710
5 changed files with 33 additions and 6 deletions
|
@ -27,6 +27,11 @@ Changelog structure reference:
|
|||
- Project
|
||||
- New project panel is now much more compact
|
||||
|
||||
### Fixed
|
||||
|
||||
- Zig
|
||||
- `zig env` failure causes an IDE error
|
||||
|
||||
## [20.3.0]
|
||||
|
||||
- Zig
|
||||
|
|
|
@ -166,7 +166,7 @@ class ZigProjectSettingsPanel(private val project: Project) : ZigProjectConfigur
|
|||
val toolchain = pathToToolchain?.let { LocalZigToolchain(it) }
|
||||
val zig = toolchain?.zig
|
||||
if (zig?.path()?.toFile()?.exists() != true) {
|
||||
toolchainVersion.text = ""
|
||||
toolchainVersion.text = "[zig binary not found]"
|
||||
|
||||
if (!stdFieldOverride.isSelected) {
|
||||
pathToStd.text = ""
|
||||
|
@ -174,6 +174,13 @@ class ZigProjectSettingsPanel(private val project: Project) : ZigProjectConfigur
|
|||
return
|
||||
}
|
||||
val env = zig.getEnv(project)
|
||||
if (env == null) {
|
||||
toolchainVersion.text = "[failed to run zig env]"
|
||||
if (!stdFieldOverride.isSelected) {
|
||||
pathToStd.text = ""
|
||||
}
|
||||
return
|
||||
}
|
||||
val version = env.version
|
||||
val stdPath = env.stdPath(toolchain, project)
|
||||
toolchainVersion.text = version
|
||||
|
|
|
@ -76,7 +76,7 @@ private fun getName(
|
|||
project: Project
|
||||
): String {
|
||||
val tc = state.toolchain ?: return "Zig"
|
||||
val version = runBlocking { tc.zig.getEnv(project).version }
|
||||
val version = runBlocking { tc.zig.getEnv(project)?.version } ?: return "Zig"
|
||||
return "Zig $version"
|
||||
}
|
||||
|
||||
|
@ -100,7 +100,7 @@ private fun getRoots(
|
|||
}
|
||||
}
|
||||
if (toolchain != null) {
|
||||
val stdPath = runBlocking { toolchain.zig.getEnv(project) }.stdPath(toolchain, project) ?: return emptySet()
|
||||
val stdPath = runBlocking { toolchain.zig.getEnv(project) }?.stdPath(toolchain, project) ?: return emptySet()
|
||||
val roots = stdPath.refreshAndFindVirtualDirectory() ?: return emptySet()
|
||||
return setOf(roots)
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ package com.falsepattern.zigbrains.project.toolchain.tools
|
|||
import com.falsepattern.zigbrains.project.toolchain.AbstractZigToolchain
|
||||
import com.falsepattern.zigbrains.project.toolchain.ZigToolchainEnvironmentSerializable
|
||||
import com.intellij.openapi.project.Project
|
||||
import kotlinx.serialization.SerializationException
|
||||
import kotlinx.serialization.json.Json
|
||||
import java.nio.file.Path
|
||||
|
||||
|
@ -36,8 +37,13 @@ class ZigCompilerTool(toolchain: AbstractZigToolchain) : ZigTool(toolchain) {
|
|||
return toolchain.pathToExecutable(toolName)
|
||||
}
|
||||
|
||||
suspend fun getEnv(project: Project?): ZigToolchainEnvironmentSerializable {
|
||||
return envJson.decodeFromString<ZigToolchainEnvironmentSerializable>(callWithArgs(toolchain.workingDirectory(project), "env").stdout)
|
||||
suspend fun getEnv(project: Project?): ZigToolchainEnvironmentSerializable? {
|
||||
val stdout = callWithArgs(toolchain.workingDirectory(project), "env").stdout
|
||||
return try {
|
||||
envJson.decodeFromString<ZigToolchainEnvironmentSerializable>(stdout)
|
||||
} catch (e: SerializationException) {
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,15 @@ class ToolchainZLSConfigProvider: SuspendingZLSConfigProvider {
|
|||
|
||||
val env = toolchain.zig.getEnv(project)
|
||||
|
||||
if (env == null) {
|
||||
Notification(
|
||||
"zigbrains-lsp",
|
||||
"Failed to evaluate zig env",
|
||||
NotificationType.ERROR
|
||||
).notify(project)
|
||||
return previous
|
||||
}
|
||||
|
||||
val exe = env.zigExecutable.toNioPathOrNull() ?: run {
|
||||
Notification(
|
||||
"zigbrains-lsp",
|
||||
|
@ -52,7 +61,7 @@ class ToolchainZLSConfigProvider: SuspendingZLSConfigProvider {
|
|||
if (!exe.toFile().exists()) {
|
||||
Notification(
|
||||
"zigbrains-lsp",
|
||||
"Zig executable does not exiust: $exe",
|
||||
"Zig executable does not exist: $exe",
|
||||
NotificationType.ERROR
|
||||
).notify(project)
|
||||
return previous
|
||||
|
|
Loading…
Add table
Reference in a new issue