lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Separate vararg from type if given

Open Rouneq opened this issue 2 years ago • 5 comments

v3.4.2

Given the following function declaration/annotation:

---Write output to the console
---@param severity loggingSeverity
---@param message number|string|table|nil A message to display to the console; can contain formatting directives for further parameters
---@vararg any
function SmallNote.Write(severity, message, ...)
    if (severity == 'trace') then
        print("Trace: ", string.format(message, ...))
    end
end

the annotation for the vararg displays with the ... right up against the specified type.

BunchedVararg

I think this should display as ...: any.

Rouneq avatar Jul 10 '22 15:07 Rouneq

This was actually an intentional choice because it distinguishes ... from named parameters and is visually similar to how many strongly-typed languages handle variadic arguments in their function declarations (see #1207). Disclaimer: I am one of the people who suggested ...typename to replace ...: typename.

flrgh avatar Jul 10 '22 19:07 flrgh

Maybe a setting?

Rouneq avatar Jul 10 '22 20:07 Rouneq

I think ...any looks more beautiful than ...: any

sumneko avatar Jul 11 '22 07:07 sumneko

From an aesthetics perspective, I disagree. ...any just runs on together and I have to stop (if only briefly) to process it. At first take, my mind just runs on past it initially. It's also inconsistent with the formatting of the other parameters.

If that's your design decision, I can live with it (even if it's not my preference). A toggle setting satisfies both sides, but I recognize it puts an additional maintenance burden on you (for something you don't believe is necessary).

Rouneq avatar Jul 11 '22 09:07 Rouneq

Since it's just a matter of personal preference, I'm not going to change it again. But I don't mind there is a PR to implement a toggle setting.

sumneko avatar Jul 11 '22 09:07 sumneko

Closing stale issue

carsakiller avatar Sep 08 '22 17:09 carsakiller