Skip to content

Commit d8409f4

Browse files
committed
improve error messages from validateServerCapabilities
1 parent 27747f4 commit d8409f4

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

src/basic_server.zig

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,14 +565,37 @@ pub fn validateServerCapabilities(comptime Handler: type, capabilities: types.Se
565565
}) |method_name, status| {
566566
switch (status) {
567567
.disabled => {
568-
if (@hasDecl(Handler, method_name)) {
569-
std.debug.panic("The client capabilities indicates that the '{s}' method is not implemented but it has been implemented in the Handler", .{method_name});
568+
if (@hasDecl(Handler, method_name) or @hasField(Handler, method_name)) {
569+
std.debug.panic(
570+
\\The LSP method {}.{} has been implemented but the server capabilities still indicate that the method hasn't been implemented.
571+
\\
572+
\\Ensure that the server capabilities which are returned during `initialize` match the implemented method.
573+
, .{
574+
Handler,
575+
std.zig.fmtId(method_name),
576+
});
570577
}
571578
},
572579
.allowed => {},
573580
.expected => {
574-
if (!@hasDecl(Handler, method_name)) {
575-
std.debug.panic("The '{s}' method has been implemented in the Handler but the client capabilities indicates that the method is not implemented", .{method_name});
581+
if (!@hasDecl(Handler, method_name) and !@hasField(Handler, method_name)) {
582+
std.debug.panic(
583+
\\The server capabilities indicate that {} is implemented in `{}` but the expected function could not be found.
584+
\\
585+
\\Make sure that a public function with the following signature has been added:
586+
\\pub fn {}(
587+
\\ handler: *Handler,
588+
\\ arena: std.mem.Allocator,
589+
\\ params: {},
590+
\\) {} {{}}
591+
\\
592+
, .{
593+
std.zig.fmtId(method_name),
594+
Handler,
595+
std.zig.fmtId(method_name),
596+
lsp.ParamsType(method_name),
597+
lsp.ResultType(method_name),
598+
});
576599
}
577600
},
578601
}

0 commit comments

Comments
 (0)