fix: Smarter toolchain path resolution
This commit is contained in:
parent
4461df14a0
commit
68d1e60b3e
2 changed files with 81 additions and 2 deletions
|
@ -17,6 +17,11 @@ Changelog structure reference:
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Fixed
|
||||
|
||||
- Project
|
||||
- Relative paths in zig toolchain configuration would break the entire IDE
|
||||
|
||||
## [17.0.0]
|
||||
|
||||
### Added
|
||||
|
|
|
@ -19,10 +19,15 @@ package com.falsepattern.zigbrains.project.toolchain;
|
|||
import com.falsepattern.zigbrains.project.openapi.components.ZigProjectSettingsService;
|
||||
import com.falsepattern.zigbrains.zig.environment.ZLSConfig;
|
||||
import com.falsepattern.zigbrains.zig.environment.ZLSConfigProvider;
|
||||
import com.intellij.notification.Notification;
|
||||
import com.intellij.notification.NotificationType;
|
||||
import com.intellij.notification.Notifications;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectUtil;
|
||||
import lombok.val;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.InvalidPathException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ToolchainZLSConfigProvider implements ZLSConfigProvider {
|
||||
|
@ -39,7 +44,76 @@ public class ToolchainZLSConfigProvider implements ZLSConfigProvider {
|
|||
state.setToolchain(toolchain);
|
||||
}
|
||||
val projectDir = ProjectUtil.guessProjectDir(project);
|
||||
val env = toolchain.zig().getEnv(projectDir == null ? Path.of(".") : projectDir.toNioPath());
|
||||
env.ifPresent(e -> builder.zig_exe_path(e.zigExecutable()).zig_lib_path(state.overrideStdPath ? Path.of(state.explicitPathToStd).getParent().toString() : e.libDirectory()));
|
||||
val oEnv = toolchain.zig().getEnv(projectDir == null ? null : projectDir.toNioPath());
|
||||
if (oEnv.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
val env = oEnv.get();
|
||||
Path exe;
|
||||
try {
|
||||
exe = Path.of(env.zigExecutable());
|
||||
} catch (InvalidPathException e) {
|
||||
Notifications.Bus.notify(new Notification("ZigBrains.Project",
|
||||
"Invalid zig executable path: " + env.zigExecutable(),
|
||||
NotificationType.ERROR));
|
||||
return;
|
||||
}
|
||||
if (!exe.isAbsolute()) {
|
||||
exe = toolchain.getLocation().resolve(exe);
|
||||
}
|
||||
if (!Files.exists(exe)) {
|
||||
Notifications.Bus.notify(new Notification("ZigBrains.Project",
|
||||
"Zig executable path does not exist: " + env.zigExecutable(),
|
||||
NotificationType.ERROR));
|
||||
return;
|
||||
}
|
||||
Path lib = null;
|
||||
override:
|
||||
if (state.overrideStdPath) {
|
||||
try {
|
||||
lib = Path.of(state.explicitPathToStd);
|
||||
} catch (InvalidPathException e) {
|
||||
Notifications.Bus.notify(new Notification("ZigBrains.Project",
|
||||
"Invalid zig standard library path override: " + env.zigExecutable(),
|
||||
NotificationType.ERROR));
|
||||
state.overrideStdPath = false;
|
||||
break override;
|
||||
}
|
||||
if (!lib.isAbsolute()) {
|
||||
lib = toolchain.getLocation().resolve(lib);
|
||||
}
|
||||
if (!Files.exists(lib)) {
|
||||
Notifications.Bus.notify(new Notification("ZigBrains.Project",
|
||||
"Zig standard library path override does not exist: " + env.zigExecutable(),
|
||||
NotificationType.ERROR));
|
||||
lib = null;
|
||||
state.overrideStdPath = false;
|
||||
break override;
|
||||
} else {
|
||||
state.explicitPathToStd = lib.toString();
|
||||
}
|
||||
}
|
||||
if (lib == null) {
|
||||
try {
|
||||
lib = Path.of(env.libDirectory());
|
||||
} catch (InvalidPathException e) {
|
||||
Notifications.Bus.notify(new Notification("ZigBrains.Project",
|
||||
"Invalid zig standard library path: " + env.zigExecutable(),
|
||||
NotificationType.ERROR));
|
||||
return;
|
||||
}
|
||||
if (!lib.isAbsolute()) {
|
||||
lib = toolchain.getLocation().resolve(lib);
|
||||
}
|
||||
if (!Files.exists(lib)) {
|
||||
Notifications.Bus.notify(new Notification("ZigBrains.Project",
|
||||
"Zig standard library path does not exist: " +
|
||||
env.zigExecutable(), NotificationType.ERROR));
|
||||
return;
|
||||
}
|
||||
}
|
||||
builder.zig_exe_path(exe.toString());
|
||||
builder.zig_lib_path(lib.toString());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue