show better zig/zls version mismatch messages (#917)

* show better zig/zls version mismatch messages

* always show message if versions don't match

* ignore patch
This commit is contained in:
Techatrix 2023-01-16 19:49:00 +01:00 committed by GitHub
parent af85a9550d
commit 9e74afada6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -188,6 +188,12 @@ fn showMessage(
args: anytype,
) void {
const message = std.fmt.allocPrint(server.arena.allocator(), fmt, args) catch return;
switch (message_type) {
.Error => log.err("{s}", .{message}),
.Warning => log.warn("{s}", .{message}),
.Info => log.info("{s}", .{message}),
.Log => log.debug("{s}", .{message}),
}
server.sendNotification("window/showMessage", types.ShowMessageParams{
.type = message_type,
.message = message,
@ -1757,12 +1763,32 @@ fn initializeHandler(server: *Server, request: types.InitializeParams) Error!typ
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 break :blk;
const zig_version = std.SemanticVersion.parse(env.version) catch break :blk;
const zls_version = comptime std.SemanticVersion.parse(build_options.version) catch unreachable;
if (zig_builtin.zig_version.order(zig_exe_version) == .gt) {
server.showMessage(.Warning,
\\ZLS was built with Zig {}, but your Zig version is {s}. Update Zig to avoid unexpected behavior.
, .{ zig_builtin.zig_version, env.version });
const zig_version_simple = std.SemanticVersion{
.major = zig_version.major,
.minor = zig_version.minor,
.patch = 0,
};
const zls_version_simple = std.SemanticVersion{
.major = zls_version.major,
.minor = zls_version.minor,
.patch = 0,
};
switch (zig_version_simple.order(zls_version_simple)) {
.lt => {
server.showMessage(.Warning,
\\Zig `{}` is older than ZLS `{}`. Update Zig to avoid unexpected behavior.
, .{ zig_version, zls_version });
},
.eq => {},
.gt => {
server.showMessage(.Warning,
\\Zig `{}` is newer than ZLS `{}`. Update ZLS to avoid unexpected behavior.
, .{ zig_version, zls_version });
},
}
} else {
server.showMessage(.Warning,