From ffb3f9440e258e9f9e5a8a7688f87ac4caa7c0c9 Mon Sep 17 00:00:00 2001 From: Techatrix <19954306+Techatrix@users.noreply.github.com> Date: Tue, 30 Aug 2022 00:46:13 +0200 Subject: [PATCH] add --show-config-path for querying the config path --- src/main.zig | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.zig b/src/main.zig index a462a87..6eafe6e 100644 --- a/src/main.zig +++ b/src/main.zig @@ -103,6 +103,7 @@ fn parseArgs( version, config, @"enable-debug-log", + @"show-config-path", @"config-path", }; const arg_id_map = std.ComptimeStringMap(ArgId, comptime blk: { @@ -126,6 +127,7 @@ fn parseArgs( .version = "Prints the compiler version with which the server was compiled.", .@"enable-debug-log" = "Enables debug logs.", .@"config-path" = "Specify the path to a configuration file specifying LSP behaviour.", + .@"show-config-path" = "Prints the path to the configuration file to stdout", .config = "Run the ZLS configuration wizard.", }); var info_it = cmd_infos.iterator(); @@ -145,6 +147,7 @@ fn parseArgs( var config_path: ?[]const u8 = null; errdefer if (config_path) |path| allocator.free(path); + const stdout = std.io.getStdOut().writer(); const stderr = std.io.getStdErr().writer(); while (args_it.next()) |tok| { @@ -173,6 +176,7 @@ fn parseArgs( .version => {}, .@"enable-debug-log" => {}, .config => {}, + .@"show-config-path" => {}, .@"config-path" => { const path = args_it.next() orelse { try stderr.print("Expected configuration file path after --config-path argument.\n", .{}); @@ -202,6 +206,22 @@ fn parseArgs( if (specified.get(.@"config-path")) { std.debug.assert(config.config_path != null); } + if (specified.get(.@"show-config-path")) { + const new_config = try getConfig(allocator, config.config_path, true); + defer if (new_config.config_path) |path| allocator.free(path); + defer std.json.parseFree(Config, new_config.config, .{ .allocator = allocator }); + + if (new_config.config_path) |path| { + const full_path = try std.fs.path.resolve(allocator, &.{ path, "zls.json" }); + defer allocator.free(full_path); + + try stdout.writeAll(full_path); + try stdout.writeByte('\n'); + } else { + logger.err("Failed to find zls.json!\n", .{}); + } + return .exit; + } return .proceed; }