improve behavior if zig_exe_path is not set (#830)

This commit is contained in:
Techatrix 2022-12-17 09:03:05 +01:00 committed by GitHub
parent d679b19676
commit 375daba743
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 14 deletions

View File

@ -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,

View File

@ -1683,17 +1683,30 @@ 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)});
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, server.config.zig_exe_path.?) orelse return;
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 });
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.
,
);
}
}
fn initializedHandler(server: *Server, writer: anytype, id: types.RequestId) !void {

View File

@ -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",