Skip to content

Commit aa3f213

Browse files
committed
Always use workspace/configuration to acquire config options if supported
For some editor, ZLS would still use the outdated push model with `workspace/didChangeConfiguration` even if they supported the pull model with `workspace/Configuration`.
1 parent 331cf1c commit aa3f213

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/Server.zig

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,9 @@ fn initializedHandler(server: *Server, arena: std.mem.Allocator, notification: t
630630

631631
server.status = .initialized;
632632

633-
if (server.client_capabilities.supports_workspace_did_change_configuration_dynamic_registration) {
633+
if (server.client_capabilities.supports_configuration and
634+
server.client_capabilities.supports_workspace_did_change_configuration_dynamic_registration)
635+
{
634636
try server.registerCapability("workspace/didChangeConfiguration", null);
635637
}
636638

@@ -961,13 +963,26 @@ fn didChangeWorkspaceFoldersHandler(server: *Server, arena: std.mem.Allocator, n
961963
fn didChangeConfigurationHandler(server: *Server, arena: std.mem.Allocator, notification: types.DidChangeConfigurationParams) Error!void {
962964
const settings = switch (notification.settings) {
963965
.null => {
964-
if (server.client_capabilities.supports_configuration) {
966+
if (server.client_capabilities.supports_configuration and
967+
server.client_capabilities.supports_workspace_did_change_configuration_dynamic_registration)
968+
{
969+
// The client has informed us that the configuration options have
970+
// changed. The will request them with `workspace/configuration`.
965971
try server.requestConfiguration();
966972
}
967973
return;
968974
},
969-
.object => |object| object.get("zls") orelse notification.settings,
970-
else => notification.settings,
975+
.object => |object| blk: {
976+
if (server.client_capabilities.supports_configuration and
977+
server.client_capabilities.supports_workspace_did_change_configuration_dynamic_registration)
978+
{
979+
log.debug("Ignoring 'workspace/didChangeConfiguration' notification in favor of 'workspace/configuration'", .{});
980+
try server.requestConfiguration();
981+
return;
982+
}
983+
break :blk object.get("zls") orelse notification.settings;
984+
},
985+
else => notification.settings, // We will definitely fail to parse this
971986
};
972987

973988
const new_config = std.json.parseFromValueLeaky(

0 commit comments

Comments
 (0)