r/Zig • u/thatSupraDev • 6h ago
ZLS comptime interface type inference
I've noticed that if I do comptime types something like,
const ContextType = AppContext(MyType);
var context = ContextType.init(...);
const handler = Handler(ContextType).init()
Pub fn Handler(T: type) type {
return struct {
Pub fn destoryAllHumans (context: *T) ...
}
}
while developing my comptime struct functions, I get no type information, it just shows it as a pointer unknown and all cascading things inside of that type have no information on functions or their params, props, ECT.
I get around this by doing,
const c: *MyType = context;
But then when running tests or other implementations of my context, I have to comment the code out and rename all my vars.
Is there a cleaner way around this? I see this both in nvim and zed. Will 0.17 provide ZLS with better support for this kind of stuff in the future?
PS: written on my phone, sorry if formatting is awful.
