From 643496922db2cf3e07e5080422b387aaa1eb7137 Mon Sep 17 00:00:00 2001 From: Ye Sijun Date: Tue, 30 May 2023 15:54:26 +0900 Subject: [PATCH] compatible with the `settings.zls` in didChangeConfigurationHandler Signed-off-by: Ye Sijun --- src/Server.zig | 7 ++++--- src/configuration.zig | 3 --- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Server.zig b/src/Server.zig index 5db176d..abcb07e 100644 --- a/src/Server.zig +++ b/src/Server.zig @@ -946,11 +946,12 @@ pub fn formattingHandler(server: *Server, request: types.DocumentFormattingParam return if (diff.edits(allocator, handle.text, formatted, server.offset_encoding)) |text_edits| text_edits.items else |_| null; } -fn didChangeConfigurationHandler(server: *Server, request: configuration.DidChangeConfigurationParams) Error!void { +fn didChangeConfigurationHandler(server: *Server, request: types.DidChangeConfigurationParams) Error!void { var new_zig_exe = false; // NOTE: VS Code seems to always respond with null - if (request.settings) |cfg| { + if (request.settings != .null) { + const cfg = tres.parse(configuration.Configuration, request.settings.object.get("zls") orelse request.settings, null) catch return; inline for (std.meta.fields(configuration.Configuration)) |field| { if (@field(cfg, field.name)) |value| { blk: { @@ -1474,7 +1475,7 @@ pub fn processMessage(server: *Server, message: Message) Error!void { .{ "textDocument/references", referencesHandler }, .{ "textDocument/documentHighlight", documentHighlightHandler }, .{ "textDocument/codeAction", codeActionHandler }, - .{ "workspace/didChangeConfiguration", didChangeConfigurationHandler }, // types.DidChangeConfigurationParams + .{ "workspace/didChangeConfiguration", didChangeConfigurationHandler }, .{ "textDocument/foldingRange", foldingRangeHandler }, .{ "textDocument/selectionRange", selectionRangeHandler }, }; diff --git a/src/configuration.zig b/src/configuration.zig index ee3ea53..a89dcb3 100644 --- a/src/configuration.zig +++ b/src/configuration.zig @@ -214,9 +214,6 @@ pub fn getZigEnv(allocator: std.mem.Allocator, zig_exe_path: []const u8) ?Env { } pub const Configuration = getConfigurationType(); -pub const DidChangeConfigurationParams = struct { - settings: ?Configuration, -}; // returns a Struct which is the same as `Config` except that every field is optional. fn getConfigurationType() type {