zigtools / zls

A Zig language server supporting Zig developers with features like autocomplete and goto definition
MIT License
3.02k stars 299 forks source link

Autocomplete should not insert parenthesis for function pointers #2012

Open IntegratedQuantum opened 2 months ago

IntegratedQuantum commented 2 months ago

Current behavior

Screenshot at 2024-08-28 10-16-38 Screenshot at 2024-08-28 10-16-43 It's easy to miss the fact that zls inserted some extra parenthesis there, and the error message of the compiler can also be pretty obscure. Overall it's really annoying to deal with.

Obscure error from the above example ``` compiler/zig/lib/std/Thread.zig:1050:30: error: unable to evaluate comptime expression return tls_thread_id orelse { ~~~~~~~~~~~~~~^~~~~~ compiler/zig/lib/std/Thread.zig:589:52: note: called from here return LinuxThreadImpl.getCurrentId(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ compiler/zig/lib/std/Thread.zig:277:29: note: called from here return Impl.getCurrentId(); ~~~~~~~~~~~~~~~~~^~ compiler/zig/lib/std/Thread/Mutex.zig:80:47: note: called from here const current_id = Thread.getCurrentId(); ~~~~~~~~~~~~~~~~~~~^~ compiler/zig/lib/std/Thread/Mutex.zig:44:19: note: called from here self.impl.lock(); ~~~~~~~~~~~~~~^~ src/game.zig:112:13: note: called from here mutex.lock(); ~~~~~~~~~~^~ src/main.zig:593:50: note: called from here currentPoint.pos = game.Player.getEyePosBlocking(); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~ src/main.zig:364:74: note: called from here .{.name = "pos", .key = c.GLFW_KEY_F9, .releaseAction = &storePosAndVel()}, ~~~~~~~~~~~~~~^~ ```

Proposed improvement

Ideally the result type should be detected, but I think that goes beyond zls's capabilities. Instead it could check if there is an ampersand in front of the function name, if there is then don't add the extra parenthesis.