improve behavior if zig_exe_path is not set (#830)
This commit is contained in:
parent
d679b19676
commit
375daba743
@ -858,10 +858,7 @@ pub fn resolveCImport(self: *DocumentStore, handle: Handle, node: Ast.Node.Index
|
||||
/// caller owns the returned memory
|
||||
pub fn uriFromImportStr(self: *const DocumentStore, allocator: std.mem.Allocator, handle: Handle, import_str: []const u8) error{OutOfMemory}!?Uri {
|
||||
if (std.mem.eql(u8, import_str, "std")) {
|
||||
const zig_lib_path = self.config.zig_lib_path orelse {
|
||||
log.debug("Cannot resolve std library import, path is null.", .{});
|
||||
return null;
|
||||
};
|
||||
const zig_lib_path = self.config.zig_lib_path orelse return null;
|
||||
|
||||
const std_path = std.fs.path.resolve(allocator, &[_][]const u8{ zig_lib_path, "./std/std.zig" }) catch |err| switch (err) {
|
||||
error.OutOfMemory => return error.OutOfMemory,
|
||||
|
@ -1683,16 +1683,29 @@ fn initializeHandler(server: *Server, writer: anytype, id: types.RequestId, req:
|
||||
log.info("{}", .{server.client_capabilities});
|
||||
log.info("Using offset encoding: {s}", .{std.meta.tagName(server.offset_encoding)});
|
||||
|
||||
// TODO avoid having to call getZigEnv twice
|
||||
// once in init and here
|
||||
const env = configuration.getZigEnv(server.allocator, server.config.zig_exe_path.?) orelse return;
|
||||
defer std.json.parseFree(configuration.Env, env, .{ .allocator = server.allocator });
|
||||
if (server.config.zig_exe_path) |exe_path| blk: {
|
||||
// TODO avoid having to call getZigEnv twice
|
||||
// once in init and here
|
||||
const env = configuration.getZigEnv(server.allocator, exe_path) orelse break :blk;
|
||||
defer std.json.parseFree(configuration.Env, env, .{ .allocator = server.allocator });
|
||||
|
||||
const zig_exe_version = std.SemanticVersion.parse(env.version) catch return;
|
||||
const zig_exe_version = std.SemanticVersion.parse(env.version) catch break :blk;
|
||||
|
||||
if (zig_builtin.zig_version.order(zig_exe_version) == .gt) {
|
||||
const version_mismatch_message = try std.fmt.allocPrint(server.arena.allocator(), "ZLS was built with Zig {}, but your Zig version is {s}. Update Zig to avoid unexpected behavior.", .{ zig_builtin.zig_version, env.version });
|
||||
try server.showMessage(writer, .Warning, version_mismatch_message);
|
||||
if (zig_builtin.zig_version.order(zig_exe_version) == .gt) {
|
||||
const version_mismatch_message = try std.fmt.allocPrint(
|
||||
server.arena.allocator(),
|
||||
"ZLS was built with Zig {}, but your Zig version is {s}. Update Zig to avoid unexpected behavior.",
|
||||
.{ zig_builtin.zig_version, env.version },
|
||||
);
|
||||
try server.showMessage(writer, .Warning, version_mismatch_message);
|
||||
}
|
||||
} else {
|
||||
try server.showMessage(
|
||||
writer,
|
||||
.Warning,
|
||||
\\ZLS failed to find Zig. Please add Zig to your PATH or set the zig_exe_path config option in your zls.json.
|
||||
,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -162,11 +162,11 @@ pub fn translate(allocator: std.mem.Allocator, config: Config, include_dirs: []c
|
||||
};
|
||||
|
||||
const base_args = &[_][]const u8{
|
||||
config.zig_exe_path.?,
|
||||
config.zig_exe_path orelse return null,
|
||||
"translate-c",
|
||||
"--enable-cache",
|
||||
"--zig-lib-dir",
|
||||
config.zig_lib_path.?,
|
||||
config.zig_lib_path orelse return null,
|
||||
"--cache-dir",
|
||||
config.global_cache_path.?,
|
||||
"-lc",
|
||||
|
Loading…
Reference in New Issue
Block a user