print zls version and path during startup (#1165)

* print zls version during startup

* print zls executable path during startup
This commit is contained in:
Lee Cannon 2023-05-02 15:54:13 -07:00 committed by GitHub
parent 3040c34d97
commit fd05faf51a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -199,6 +199,8 @@ const ParseArgsResult = struct {
replay_enabled: bool, replay_enabled: bool,
replay_session_path: ?[]const u8, replay_session_path: ?[]const u8,
message_tracing_enabled: bool, message_tracing_enabled: bool,
zls_exe_path: []const u8,
}; };
fn parseArgs(allocator: std.mem.Allocator) !ParseArgsResult { fn parseArgs(allocator: std.mem.Allocator) !ParseArgsResult {
@ -208,6 +210,7 @@ fn parseArgs(allocator: std.mem.Allocator) !ParseArgsResult {
.replay_enabled = false, .replay_enabled = false,
.replay_session_path = null, .replay_session_path = null,
.message_tracing_enabled = false, .message_tracing_enabled = false,
.zls_exe_path = undefined,
}; };
const ArgId = enum { const ArgId = enum {
@ -256,7 +259,10 @@ fn parseArgs(allocator: std.mem.Allocator) !ParseArgsResult {
var args_it = try std.process.ArgIterator.initWithAllocator(allocator); var args_it = try std.process.ArgIterator.initWithAllocator(allocator);
defer args_it.deinit(); defer args_it.deinit();
if (!args_it.skip()) @panic("Could not find self argument");
if (args_it.next()) |zls_path| {
result.zls_exe_path = try allocator.dupe(u8, zls_path);
} else unreachable;
// Makes behavior of enabling debug more logging consistent regardless of argument order. // Makes behavior of enabling debug more logging consistent regardless of argument order.
var specified = std.enums.EnumArray(ArgId, bool).initFill(false); var specified = std.enums.EnumArray(ArgId, bool).initFill(false);
@ -366,6 +372,7 @@ pub fn main() !void {
const allocator: std.mem.Allocator = if (build_options.enable_failing_allocator) failing_allocator_state.allocator() else inner_allocator; const allocator: std.mem.Allocator = if (build_options.enable_failing_allocator) failing_allocator_state.allocator() else inner_allocator;
const result = try parseArgs(allocator); const result = try parseArgs(allocator);
defer allocator.free(result.zls_exe_path);
defer if (result.config_path) |path| allocator.free(path); defer if (result.config_path) |path| allocator.free(path);
defer if (result.replay_session_path) |path| allocator.free(path); defer if (result.replay_session_path) |path| allocator.free(path);
switch (result.action) { switch (result.action) {
@ -373,6 +380,8 @@ pub fn main() !void {
.exit => return, .exit => return,
} }
logger.info("Starting ZLS {s} @ '{s}'", .{ build_options.version, result.zls_exe_path });
var config = try getConfig(allocator, result.config_path); var config = try getConfig(allocator, result.config_path);
defer std.json.parseFree(Config, config.config, .{ .allocator = allocator }); defer std.json.parseFree(Config, config.config, .{ .allocator = allocator });
defer if (config.config_path) |path| allocator.free(path); defer if (config.config_path) |path| allocator.free(path);