zls icon indicating copy to clipboard operation
zls copied to clipboard

Add referenced, but not implemented, methods to function autocomplete

Open mnemnion opened this issue 1 year ago • 2 comments

Say I'm working on a function, and realize I'll need another method to finish it:

pub fn doingSomething(self: @This(), param: SomeParameter) void {
     // stuff 
     const return = self.doSomethingNew(value);
}

In my color scheme, doSomethingNew will be white instead of green, because it doesn't exist. Your highlights may vary.

What would be nice is, when I go to implement it, I get a completion:

fn d| // This offers doSomethingNew as a completion

In addition to the convenience, it means I know that the name of the method I'm implementing is the name which I already gave it. Sort of like the very nice feature in switch statements where the completions only contain unreferenced enums, so if you don't get a completion you know you've covered all cases, in this case if there are no completions then I'd know that I don't have any method stubs in the code which need to be written out.

There are some more advanced things which could be done, in terms of filling in the types based on what the prior code passes them, but just the completion would be a great feature.

mnemnion avatar Oct 16 '24 18:10 mnemnion

There could also be a code action that would create the missing function. Here is an example with typescript-language-server in VS Code:

https://github.com/user-attachments/assets/1f041549-255c-446f-a8a0-f3282f28676e

Implementing this would require more reliable type information.

Techatrix avatar Oct 22 '24 12:10 Techatrix

That would be a lovely stretch goal, indeed. I can see where the general comptime and return-type-inference challenges with type info would apply there as well.

Even moving whatever information tells the language server that a nonexistent function shouldn't be function-colored, to the declaration-level autocomplete context, would be a solid quality-of-life feature.

mnemnion avatar Oct 23 '24 15:10 mnemnion