LuaLS / lua-language-server

A language server that offers Lua language support - programmed in Lua
https://luals.github.io
MIT License
3.26k stars 306 forks source link

Feature Request/How-to: Inlined parameter annotation #2250

Open BribeFromTheHive opened 1 year ago

BribeFromTheHive commented 1 year ago

I'd like to be able to do inlined type annotation for parameters. It doesn't currently seem to be possible. What I mean is, instead of this:

---@param key                       unknown
---@param callbackFn                fun(Hook, ...):any
---@param priority?                 number
---@param hostTableToHook?          table
---@param defaultNativeBehavior?    function
---@param hookedTableIsMetaTable?   boolean
function Hook.basic(key, callbackFn, priority, hostTableToHook, defaultNativeBehavior, hookedTableIsMetaTable)
    return Hook.add(key, callbackFn, priority, hostTableToHook, defaultNativeBehavior, hookedTableIsMetaTable, true)
end

I'd like to be able to do this:

function Hook.basic(
    key,                    ---@param unknown
    callbackFn,             ---@param fun(Hook, ...):any
    priority,               ---@param? number
    hostTableToHook,        ---@param? table
    defaultNativeBehavior,  ---@param? function
    hookedTableIsMetaTable  ---@param? boolean
)
    return Hook.add(key, callbackFn, priority, hostTableToHook, defaultNativeBehavior, hookedTableIsMetaTable, true)
end

This would cut down on the boilerplate a bit and make the code cleaner.

C3pa commented 1 year ago

IMHO, having only one way to annotate the parameters is better. The proposal doesn't reduce the needed effort by much. Also, it introduced another new concept not existent in the current LuaCATS: ---@param? - another way to annotate optional argument. I am against that.

BribeFromTheHive commented 1 year ago

IMHO, having only one way to annotate the parameters is better. The proposal doesn't reduce the needed effort by much. Also, it introduced another new concept not existent in the current LuaCATS: ---@param? - another way to annotate optional argument. I am against that.

That is totally valid. I am only putting out opinions. I am leaning more towards TSTL for the longer term at this point, as I don’t think that EmmyLua’s JSDoc-type stuff is convenient for quick coding.

Frityet commented 1 year ago

IMHO, having only one way to annotate the parameters is better. The proposal doesn't reduce the needed effort by much. Also, it introduced another new concept not existent in the current LuaCATS: ---@param? - another way to annotate optional argument. I am against that.

That is totally valid. I am only putting out opinions. I am leaning more towards TSTL for the longer term at this point, as I don’t think that EmmyLua’s JSDoc-type stuff is convenient for quick coding.

Check out teal

Frityet commented 1 year ago

IMHO, having only one way to annotate the parameters is better. The proposal doesn't reduce the needed effort by much. Also, it introduced another new concept not existent in the current LuaCATS: ---@param? - another way to annotate optional argument. I am against that.


---@param x integer
---@param y integer?
local function my_function(x, y)

end
``` why `?` on the `param`
sumneko commented 1 year ago

It might be possible to support ---@type. However, since it's only a syntax sugar proposal, I won't consider adding support for it at the moment.