zigtools / zls

A Zig language server supporting Zig developers with features like autocomplete and goto definition
MIT License
3.02k stars 299 forks source link

Autocomplete and hover information for decl literals #2027

Open IntegratedQuantum opened 2 months ago

IntegratedQuantum commented 2 months ago

This is a fairly new addition to the language (https://github.com/ziglang/zig/pull/21264) and it would be nice if zls would autocomplete these, and show some more information (like function parameters and doc comments) when hovering over a decl literal.

llogick commented 2 months ago

Some alpha state code

Maybe someone will come up with a neat way to type match declarations and definitions?

Examples given in the original ziglang proposal were

test {
    const s: ?**const S = try .getGlobal();
    _ = s;
}

const S = struct {
    x: usize,
    var g: *const S = &.{ .x = 1 };
    fn getGlobal() anyerror!?**const S {
        return &g;
    }
};

and

const S = struct {
    const init: anyerror!anyerror!????S = .{};
};

test {
    const s: ????S = try try .init;
    _ = s;
}

(doubt it's practicality, but apparently it passes)