Merge pull request #614 from Techatrix/show-config-path

add --show-config-path for querying the config path
This commit is contained in:
Lee Cannon 2022-08-30 18:22:50 +01:00 committed by GitHub
commit da03c81992
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -103,6 +103,7 @@ fn parseArgs(
version, version,
config, config,
@"enable-debug-log", @"enable-debug-log",
@"show-config-path",
@"config-path", @"config-path",
}; };
const arg_id_map = std.ComptimeStringMap(ArgId, comptime blk: { 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.", .version = "Prints the compiler version with which the server was compiled.",
.@"enable-debug-log" = "Enables debug logs.", .@"enable-debug-log" = "Enables debug logs.",
.@"config-path" = "Specify the path to a configuration file specifying LSP behaviour.", .@"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.", .config = "Run the ZLS configuration wizard.",
}); });
var info_it = cmd_infos.iterator(); var info_it = cmd_infos.iterator();
@ -145,6 +147,7 @@ fn parseArgs(
var config_path: ?[]const u8 = null; var config_path: ?[]const u8 = null;
errdefer if (config_path) |path| allocator.free(path); errdefer if (config_path) |path| allocator.free(path);
const stdout = std.io.getStdOut().writer();
const stderr = std.io.getStdErr().writer(); const stderr = std.io.getStdErr().writer();
while (args_it.next()) |tok| { while (args_it.next()) |tok| {
@ -173,6 +176,7 @@ fn parseArgs(
.version => {}, .version => {},
.@"enable-debug-log" => {}, .@"enable-debug-log" => {},
.config => {}, .config => {},
.@"show-config-path" => {},
.@"config-path" => { .@"config-path" => {
const path = args_it.next() orelse { const path = args_it.next() orelse {
try stderr.print("Expected configuration file path after --config-path argument.\n", .{}); try stderr.print("Expected configuration file path after --config-path argument.\n", .{});
@ -202,6 +206,22 @@ fn parseArgs(
if (specified.get(.@"config-path")) { if (specified.get(.@"config-path")) {
std.debug.assert(config.config_path != null); 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; return .proceed;
} }