You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bad completion and signature help on functions assigned to const #3282
ZLS show completion and signature help for different parameter than cursor is at when the method has been assigned to a const.
This is particularly bad when working with files generated by translate c, but I also noticed the issue with my own structures which have functions generated in comptime.
constother_file=struct {
fntestFn(_: Test, _: enum{yes, no}) void { }
};
constTest=struct {
idk: usize=6,
pubconsttestFn=other_file.testFn;
};
comptime {
constidk: Test=undefined;
idk.testFn(param: enum {...}) // completed by selecting testFn completion on idk.<cursor>: already OKidk.testFn(.<cursor>) // no completionidk.testFn(undefined, .<cursor>) // yes/no enum completionidk.testFn(.yes) // signature help on ".yes" points to "_: Test"idk.testFn(.yes) // go to reference on ".yes" goes to "yes" in "_: enum{yes, no}": already OK
}
Expected Behavior
idk.testFn(param: enum {...}) // // completed by selecting testFn completion on idk.<cursor>: already OKidk.testFn(.<cursor>) // yes/no completionidk.testFn(undefined, .<cursor>) // no completion - parameter at that index does not existidk.testFn(.yes) // signature help on ".yes" points to "_: enum{yes, no}"idk.testFn(.yes) // go to reference on ".yes" goes to "yes" in "_: enum{yes, no}": already OK
I made little progress on this. I managed to fix a test regarding this that I added. I thought the issue was that a hasSelfParam function returned false for the function in question. But fixing that broke one of the assertions (the last one) in completion "function alias" test which apparently relied on the broken hasSelfParam, and one more test that seemed to have suffered from the same issue. Not fully understanding what is going on, not sure if hasSelfParam is wrong or is just being given wrong data, I took a step back and started debugging to understand more. Eventually as I learned debugging what exactly is being inspected (some dedicated debug utils would be really nice), I found that hasSelfParam = false was reported for fn foo in
constS=struct {
fnfoo(_: S, _: enum{ alpha, beta }) void {} // reported has self param = false during getting completions for s.barconstbar=foo;
};
consts: S=undefined;
constbaz=s.bar(.<cursor>); // missing completons, if I add fields on S, it tries to complete fields of S
And since there was a condition for namespace I made sure that it is being badly reported also for non-namespaces - for non namespaces it just tries to complete fields of the container.
So I came to the conclusion that the hasSelfParam is indeed wrong and needs to be fixed. So my fix of hasSelfParam, while maybe correct, broke other things that rely on hasSelfParam being wrong. So I will see if I can fix that too...
Yes hasSelfParam is indeed flawed for the following reasons:
Namespaces (struct with no fields) can actually be called with the my_namespace.my_func() syntax. Related Methods on namespaces #3278
It compares the first parameter with the container type the function is defined in as opposed to using the type of foo in foo.my_func() which doesn't have to be same because my_func might be an alias.
I addressed this for signature help by replacing hasSelfParam with firstParamIs in #3290. The same should be done for autocomplete which I haven't look much into yet. Let me know if I can do anything to assist.
Activity
psznm commentedon Oct 17, 2026
I made little progress on this. I managed to fix a test regarding this that I added. I thought the issue was that a
hasSelfParamfunction returned false for the function in question. But fixing that broke one of the assertions (the last one) in completion "function alias" test which apparently relied on the brokenhasSelfParam, and one more test that seemed to have suffered from the same issue. Not fully understanding what is going on, not sure ifhasSelfParamis wrong or is just being given wrong data, I took a step back and started debugging to understand more. Eventually as I learned debugging what exactly is being inspected (some dedicated debug utils would be really nice), I found that hasSelfParam = false was reported forfn fooinAnd since there was a condition for namespace I made sure that it is being badly reported also for non-namespaces - for non namespaces it just tries to complete fields of the container.
So I came to the conclusion that the
hasSelfParamis indeed wrong and needs to be fixed. So my fix ofhasSelfParam, while maybe correct, broke other things that rely onhasSelfParambeing wrong. So I will see if I can fix that too...techatrix commentedon Oct 17, 2026
Yes
hasSelfParamis indeed flawed for the following reasons:my_namespace.my_func()syntax. Related Methods on namespaces #3278fooinfoo.my_func()which doesn't have to be same becausemy_funcmight be an alias.I addressed this for signature help by replacing
hasSelfParamwithfirstParamIsin #3290. The same should be done for autocomplete which I haven't look much into yet. Let me know if I can do anything to assist.