@@ -618,30 +618,14 @@ fn MessageType(comptime Handler: type) type {
618618 }
619619 }
620620
621- var enum_fields : [methods .len + 1 ]std.builtin.Type.EnumField = undefined ;
622- for (enum_fields [0 .. enum_fields .len - 1 ], methods , 0.. ) | * field , method , i | field .* = .{ .name = method , .value = i };
623- enum_fields [methods .len ] = .{ .name = "other" , .value = methods .len };
624-
625- const MethodEnum = @Type (.{ .@"enum" = .{
626- .tag_type = std .math .IntFittingRange (0 , methods .len ),
627- .fields = & enum_fields ,
628- .decls = &.{},
629- .is_exhaustive = true ,
630- } });
631-
632- var union_fields : [methods .len + 1 ]std.builtin.Type.UnionField = undefined ;
633- for (union_fields [0 .. union_fields .len - 1 ], methods ) | * field , method | {
634- const field_type = lsp .ParamsType (method );
635- field .* = .{ .name = method , .type = field_type , .alignment = @alignOf (field_type ) };
636- }
637- union_fields [methods .len ] = .{ .name = "other" , .type = lsp .MethodWithParams , .alignment = @alignOf (lsp .MethodWithParams ) };
638-
639- Params .* = @Type (.{ .@"union" = .{
640- .layout = .auto ,
641- .tag_type = MethodEnum ,
642- .fields = & union_fields ,
643- .decls = &.{},
644- } });
621+ const field_names : []const []const u8 = methods ++ .{"other" };
622+ var field_types : [methods .len + 1 ]type = undefined ;
623+ for (field_types [0 .. field_types .len - 1 ], methods ) | * ty , method | ty .* = lsp .ParamsType (method );
624+ field_types [methods .len ] = lsp .MethodWithParams ;
625+
626+ const IntTag = std .math .IntFittingRange (0 , methods .len );
627+ const MethodEnum = @Enum (IntTag , .exhaustive , field_names , & std .simd .iota (IntTag , methods .len + 1 ));
628+ Params .* = @Union (.auto , MethodEnum , field_names , & field_types , &@splat (.{}));
645629 }
646630
647631 return lsp .Message (RequestParams , NotificationParams , .{});
0 commit comments