Skip to content

Commit 3b26e57

Browse files
committed
move RequestParams and NotificationParams into separate parameters
Otherwise ZLS will not be able to resolve these types. :(
1 parent f691015 commit 3b26e57

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/lsp.zig

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1663,7 +1663,9 @@ pub const MethodWithParams = struct {
16631663
params: ?std.json.Value,
16641664
};
16651665

1666-
pub const MessageConfig = struct {
1666+
pub const MessageConfig = struct {};
1667+
1668+
pub fn Message(
16671669
/// Must be a tagged union with the following properties:
16681670
/// - the field name is the method name of a request message
16691671
/// - the field type must be the params type of the method (i.e. `ParamsType(field.name)`)
@@ -1684,7 +1686,7 @@ pub const MessageConfig = struct {
16841686
/// other: MethodWithParams,
16851687
/// }
16861688
/// ```
1687-
RequestParams: type,
1689+
comptime RequestParams: type,
16881690
/// Must be a tagged union with the following properties:
16891691
/// - the field name is the method name of a notification message
16901692
/// - the field type must be the params type of the method (i.e. `ParamsType(field.name)`)
@@ -1705,11 +1707,11 @@ pub const MessageConfig = struct {
17051707
/// other: MethodWithParams,
17061708
/// }
17071709
/// ```
1708-
NotificationParams: type,
1709-
};
1710-
1711-
pub fn Message(comptime config: MessageConfig) type {
1712-
// TODO validate `config.RequestParams` and `config.NotificationParams`
1710+
comptime NotificationParams: type,
1711+
config: MessageConfig,
1712+
) type {
1713+
_ = config;
1714+
// TODO validate `RequestParams` and `NotificationParams`
17131715
// This level of comptime should be illegal...
17141716
return union(enum) {
17151717
request: Request,
@@ -1723,7 +1725,7 @@ pub fn Message(comptime config: MessageConfig) type {
17231725
id: JsonRPCMessage.ID,
17241726
params: Params,
17251727

1726-
pub const Params = config.RequestParams;
1728+
pub const Params = RequestParams;
17271729

17281730
pub const jsonParse = @compileError("Parsing a Request directly is not implemented! try to parse the Message instead.");
17291731
pub const jsonParseFromValue = @compileError("Parsing a Request directly is not implemented! try to parse the Message instead.");
@@ -1747,7 +1749,7 @@ pub fn Message(comptime config: MessageConfig) type {
17471749
comptime jsonrpc: []const u8 = "2.0",
17481750
params: Params,
17491751

1750-
pub const Params = config.NotificationParams;
1752+
pub const Params = NotificationParams;
17511753

17521754
pub const jsonParse = @compileError("Parsing a Notification directly is not implemented! try to parse the Message instead.");
17531755
pub const jsonParseFromValue = @compileError("Parsing a Notification directly is not implemented! try to parse the Message instead.");
@@ -2243,10 +2245,7 @@ const ExampleNotificationMethods = union(enum) {
22432245
other: MethodWithParams,
22442246
};
22452247

2246-
const ExampleMessage = Message(.{
2247-
.RequestParams = ExampleRequestMethods,
2248-
.NotificationParams = ExampleNotificationMethods,
2249-
});
2248+
const ExampleMessage = Message(ExampleRequestMethods, ExampleNotificationMethods, .{});
22502249

22512250
fn testMessage(message: ExampleMessage, json_message: []const u8) !void {
22522251
try testMessageWithOptions(message, json_message, .{});

0 commit comments

Comments
 (0)