EmmyLua / IntelliJ-EmmyLua

Lua IDE/Debugger Plugin for IntelliJ IDEA
https://emmylua.github.io
Apache License 2.0
1.75k stars 292 forks source link

[Feature] Default argument value for @overload annotation #222

Open adriweb opened 5 years ago

adriweb commented 5 years ago

Not an issue but a feature suggestion:

As we can see in https://github.com/EmmyLua/IntelliJ-EmmyLua/blob/68e6d6e/src/main/resources/std/Lua51/table.lua#L22-L24 it's possible to annotate optional parameters with the @overload annotation (BTW, it's not mentioned in the docs, only in the changelogs).

The issue is that it's not possible to indicate if such optional parameters have a default value. This is actually very useful when reading code (and writing, with autocompletion...) so that we don't have to actually go look at the source of said function.

LDoc handles that with -- @tparam[opt="MyDefaultStringValue"] string fooVar the name of my foo.

Could we have something like this in EmmyLua?

What about supporting name:type=value in the syntax, like the following:

---@overload fun(list:table):string
---@overload fun(list:table, sep:string="", i:number=1, j:number=1):string

This was an all-at-once definition, but we could also imagine supporting one-by-one, like closer to the current impl. However in Lua it's totally possible to have a default argument not only at the end, the function itself would just check if the value of the nth arg is nil (and give it the default value) while the nth+1 one could be non-nil... So I'd prefer writing docs in the former fashion rather than the following one:

---@overload fun(list:table):string
---@overload fun(list:table, sep:string=""):string
---@overload fun(list:table, sep:string, i:number=1):string
---@overload fun(list:table, sep:string, i:number, j:number=1):string

As you can see, this one is quite verbose and basically quite uselessly too long, compared to the "all-at-once" syntax proposal.

baluballa commented 4 years ago

Would anyway be a nice feature to suppress or have an option to suppress LuaDoc errors in the PROBLEMS pane in VS Code. It is very "noisy" when you need to work with a LUA file that already is tagged with lua doc directives.

BrianOstrander commented 2 months ago

This would be great