Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Provides the necessary building blocks to develop Language Server Protocol imple
# Installation

> [!NOTE]
> The default branch requires Zig `0.16.0-dev.1204+389368392` or later. Checkout the `0.15.x` branch when using Zig 0.15
> The default branch requires Zig `0.16.0-dev.1458+755a3d957` or later. Checkout the `0.15.x` branch when using Zig 0.15

```bash
# Initialize a `zig build` project if you haven't already
Expand Down
2 changes: 1 addition & 1 deletion build.zig.zon
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.{
.name = .lsp_kit,
.version = "0.1.0",
.minimum_zig_version = "0.16.0-dev.1204+389368392",
.minimum_zig_version = "0.16.0-dev.1458+755a3d957",
.dependencies = .{},
.paths = .{
"build.zig",
Expand Down
32 changes: 8 additions & 24 deletions src/basic_server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -618,30 +618,14 @@ fn MessageType(comptime Handler: type) type {
}
}

var enum_fields: [methods.len + 1]std.builtin.Type.EnumField = undefined;
for (enum_fields[0 .. enum_fields.len - 1], methods, 0..) |*field, method, i| field.* = .{ .name = method, .value = i };
enum_fields[methods.len] = .{ .name = "other", .value = methods.len };

const MethodEnum = @Type(.{ .@"enum" = .{
.tag_type = std.math.IntFittingRange(0, methods.len),
.fields = &enum_fields,
.decls = &.{},
.is_exhaustive = true,
} });

var union_fields: [methods.len + 1]std.builtin.Type.UnionField = undefined;
for (union_fields[0 .. union_fields.len - 1], methods) |*field, method| {
const field_type = lsp.ParamsType(method);
field.* = .{ .name = method, .type = field_type, .alignment = @alignOf(field_type) };
}
union_fields[methods.len] = .{ .name = "other", .type = lsp.MethodWithParams, .alignment = @alignOf(lsp.MethodWithParams) };

Params.* = @Type(.{ .@"union" = .{
.layout = .auto,
.tag_type = MethodEnum,
.fields = &union_fields,
.decls = &.{},
} });
const field_names: []const []const u8 = methods ++ .{"other"};
var field_types: [methods.len + 1]type = undefined;
for (field_types[0 .. field_types.len - 1], methods) |*ty, method| ty.* = lsp.ParamsType(method);
field_types[methods.len] = lsp.MethodWithParams;

const IntTag = std.math.IntFittingRange(0, methods.len);
const MethodEnum = @Enum(IntTag, .exhaustive, field_names, &std.simd.iota(IntTag, methods.len + 1));
Params.* = @Union(.auto, MethodEnum, field_names, &field_types, &@splat(.{}));
}

return lsp.Message(RequestParams, NotificationParams, .{});
Expand Down