zls
zls copied to clipboard
Allow viewing all computed error variants for anyerror function return catch captures
Hello, it would be amazing if we could view all computed error variants in the popup for the captured error. I do know that zig has some way to get the error variants for a function as shown by running the following program:
const E = error{ A, B, C };
fn magicBox(n: u8) !u8 {
return switch (n) {
0 => error.A,
1 => error.B,
2 => error.C,
else => n,
};
}
pub fn main() !void {
magicBox(5) catch |e| switch (e) {};
}
Gives us errors for each of the unhandled error variants in the switch:
./example.zig:15:27: error: error.A not handled in switch
magicBox(5) catch |e| switch (e) {};
^
./example.zig:14:21: note: referenced here
pub fn main() !void {
^
/opt/compiler-explorer/zig-0.9.0/lib/std/start.zig:553:40: note: referenced here
const result = root.main() catch |err| {
^
./example.zig:15:27: error: error.B not handled in switch
magicBox(5) catch |e| switch (e) {};
^
./example.zig:15:27: error: error.C not handled in switch
magicBox(5) catch |e| switch (e) {};
Personally, I would like it if when you scrolled over the captured e, it would show something like error{ A, B, C } which includes all of the variants.
I know this would take a bit of work, and I don't have time right now to contribute. But, it would be great so I'll just mark it down here as a wish in a bottle until I possibly attempt to implement it. Thanks
blocked on #552