zls icon indicating copy to clipboard operation
zls copied to clipboard

Identify methods with first arg type for completion on non-method

Open martazvch opened this issue 11 months ago • 1 comments

When working on a structure, ZLS offers completion for methods inside a non-method. What I mean by that is that if a function defined on a structure isn't a method (first parameter structure's type), it should not be able to access methods like:

image

Here, fn4 isn't a method and yet completion shows all methods with matching name.

If there is a way to identify the first parameter's type and notice that it's a method, we could even go a step further and show completion to "smart insert" methods like in Rust:

image

martazvch avatar Jan 08 '25 20:01 martazvch

theres nothing stopping you from using any of those other functions from within fn4, you might have/create an instance of Foo. methods arent anything magical in zig

xdBronch avatar Jan 08 '25 20:01 xdBronch