fixed jrpc config treating empty strings as non null (#727)

This commit is contained in:
musi-musi 2022-10-30 00:30:03 -04:00 committed by GitHub
parent 7a7576c06d
commit 2ae113ddcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2120,10 +2120,17 @@ fn didChangeConfigurationHandler(server: *Server, writer: anytype, id: types.Req
if (req.settings) |configuration| { if (req.settings) |configuration| {
inline for (std.meta.fields(Config.Configuration)) |field| { inline for (std.meta.fields(Config.Configuration)) |field| {
if (@field(configuration, field.name)) |value| { if (@field(configuration, field.name)) |value| {
blk: {
if (@TypeOf(value) == []const u8) {
if (value.len == 0) {
break :blk;
}
}
@field(server.config, field.name) = if (@TypeOf(value) == []const u8) try server.allocator.dupe(u8, value) else value; @field(server.config, field.name) = if (@TypeOf(value) == []const u8) try server.allocator.dupe(u8, value) else value;
log.debug("setting configuration option '{s}' to '{any}'", .{ field.name, value }); log.debug("setting configuration option '{s}' to '{any}'", .{ field.name, value });
} }
} }
}
try server.config.configChanged(server.allocator, null); try server.config.configChanged(server.allocator, null);
} else if (server.client_capabilities.supports_configuration) { } else if (server.client_capabilities.supports_configuration) {
@ -2653,6 +2660,14 @@ pub fn processJsonRpc(server: *Server, writer: anytype, json: []const u8) !void
const new_value: field.field_type = switch (ft) { const new_value: field.field_type = switch (ft) {
[]const u8 => switch (value) { []const u8 => switch (value) {
.String => |s| blk: { .String => |s| blk: {
if (s.len == 0) {
if (field.field_type == ?[]const u8) {
break :blk null;
}
else {
break :blk s;
}
}
var nv = try server.allocator.dupe(u8, s); var nv = try server.allocator.dupe(u8, s);
if (@field(server.config, field.name)) |prev_val| server.allocator.free(prev_val); if (@field(server.config, field.name)) |prev_val| server.allocator.free(prev_val);
break :blk nv; break :blk nv;