zls icon indicating copy to clipboard operation
zls copied to clipboard

MultiArrayList type information

Open Crumbed opened this issue 1 month ago • 0 comments

ZLS fails to give type information when using MultiArrayList, here's an example:

const Foo = struct {
    bar: usize,
    baz: []const u8,
};

pub fn main() !void {
    var structs = std.MultiArrayList(Foo).empty;
    try structs.setCapacity(std.heap.page_allocator, 1);
    defer structs.deinit(std.heap.page_allocator);

    structs.appendAssumeCapacity(.{ .bar = 1, .baz = "first" });
    const bar = structs.items(.bar)[0];
}

bar is an unknown type, also structs.items(<field name>) gives no suggestions. My understanding of why is that zls can't evaluate comptime code, but I would think that standard library code would be an exception, especially something like this which is generating an enum off of information that zls already has.

Maybe this hasn't been done yet because zig is still in early development, but it would be very useful.

Crumbed avatar Dec 11 '25 02:12 Crumbed