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
|
- Project
|
||||||
- New project panel is now much more compact
|
- New project panel is now much more compact
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Zig
|
||||||
|
- `zig env` failure causes an IDE error
|
||||||
|
|
||||||
## [20.3.0]
|
## [20.3.0]
|
||||||
|
|
||||||
- Zig
|
- Zig
|
||||||
|
|
|
@ -166,7 +166,7 @@ class ZigProjectSettingsPanel(private val project: Project) : ZigProjectConfigur
|
||||||
val toolchain = pathToToolchain?.let { LocalZigToolchain(it) }
|
val toolchain = pathToToolchain?.let { LocalZigToolchain(it) }
|
||||||
val zig = toolchain?.zig
|
val zig = toolchain?.zig
|
||||||
if (zig?.path()?.toFile()?.exists() != true) {
|
if (zig?.path()?.toFile()?.exists() != true) {
|
||||||
toolchainVersion.text = ""
|
toolchainVersion.text = "[zig binary not found]"
|
||||||
|
|
||||||
if (!stdFieldOverride.isSelected) {
|
if (!stdFieldOverride.isSelected) {
|
||||||
pathToStd.text = ""
|
pathToStd.text = ""
|
||||||
|
@ -174,6 +174,13 @@ class ZigProjectSettingsPanel(private val project: Project) : ZigProjectConfigur
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val env = zig.getEnv(project)
|
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 version = env.version
|
||||||
val stdPath = env.stdPath(toolchain, project)
|
val stdPath = env.stdPath(toolchain, project)
|
||||||
toolchainVersion.text = version
|
toolchainVersion.text = version
|
||||||
|
|
|
@ -76,7 +76,7 @@ private fun getName(
|
||||||
project: Project
|
project: Project
|
||||||
): String {
|
): String {
|
||||||
val tc = state.toolchain ?: return "Zig"
|
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"
|
return "Zig $version"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ private fun getRoots(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (toolchain != null) {
|
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()
|
val roots = stdPath.refreshAndFindVirtualDirectory() ?: return emptySet()
|
||||||
return setOf(roots)
|
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.AbstractZigToolchain
|
||||||
import com.falsepattern.zigbrains.project.toolchain.ZigToolchainEnvironmentSerializable
|
import com.falsepattern.zigbrains.project.toolchain.ZigToolchainEnvironmentSerializable
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
|
import kotlinx.serialization.SerializationException
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
|
|
||||||
|
@ -36,8 +37,13 @@ class ZigCompilerTool(toolchain: AbstractZigToolchain) : ZigTool(toolchain) {
|
||||||
return toolchain.pathToExecutable(toolName)
|
return toolchain.pathToExecutable(toolName)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getEnv(project: Project?): ZigToolchainEnvironmentSerializable {
|
suspend fun getEnv(project: Project?): ZigToolchainEnvironmentSerializable? {
|
||||||
return envJson.decodeFromString<ZigToolchainEnvironmentSerializable>(callWithArgs(toolchain.workingDirectory(project), "env").stdout)
|
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)
|
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 {
|
val exe = env.zigExecutable.toNioPathOrNull() ?: run {
|
||||||
Notification(
|
Notification(
|
||||||
"zigbrains-lsp",
|
"zigbrains-lsp",
|
||||||
|
@ -52,7 +61,7 @@ class ToolchainZLSConfigProvider: SuspendingZLSConfigProvider {
|
||||||
if (!exe.toFile().exists()) {
|
if (!exe.toFile().exists()) {
|
||||||
Notification(
|
Notification(
|
||||||
"zigbrains-lsp",
|
"zigbrains-lsp",
|
||||||
"Zig executable does not exiust: $exe",
|
"Zig executable does not exist: $exe",
|
||||||
NotificationType.ERROR
|
NotificationType.ERROR
|
||||||
).notify(project)
|
).notify(project)
|
||||||
return previous
|
return previous
|
||||||
|
|
Loading…
Add table
Reference in a new issue