zls
zls copied to clipboard
no enum/decl literal completion in target expression of switch case
Zig Version
0.15.0-dev.441+c1649d586
ZLS Version
0.15.0-dev.137+f6580bf8
Client / Code Editor / Extensions
vscode
Steps to Reproduce and Observed Behavior
const S = enum {
a,
b,
const c: S = .a;
};
test {
const x: S = switch (@as(u8, 42)) {
0 => .<cursor>,
1 => .b,
else => .c,
};
}
Expected Behavior
shows a, b, and c
Relevant log output
Upon further inspection, it appears the Zig parser does not create an AST node for the switch statement, which means we can't use ast.nodesOverlappingIndexIncludingParseErrors
An error tolerant version of the parseSwitchProng() call in the parser might look like this:
const maybe_item = p.parseSwitchProng() catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
error.ParseError => {
p.findNextSwitchProng();
continue;
},
};
const item = maybe_item orelse break;
Then we can check for a => token to the left of the enum/decl literal and use the switch condition for type resolution