EmmyLua / IntelliJ-EmmyLua

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

Annotation for function params in table #479

Open Harrith opened 2 years ago

Harrith commented 2 years ago

Hello,

I would like to ask if is somehow possible to set type of the params of the functions in table in one place. Here is an example of the table:

local test =
{
    [0] = function (var) <some stuff> end,
    [1] = function (var) <some other stuff> end,
}

I know that the variable "var" will always be for example an integer. So I wanted to add ---@type table<integer, fun(var: integer)> above the table "test" like this:

---@type table<integer, fun(var: integer)>
local test =
{
    [0] = function (var) <some stuff> end,
    [1] = function (var) <some other stuff> end,
}

Unfortunatelly this does not work and IDE does not know that var is an integer. I am using VS Code. I have a workaround for this if I specify param for each function like this:

local test =
{
    ---@param var integer
    [0] = function(var) <some stuff> end,
    ---@param var integer
    [1] = function(var) <some other stuff> end,
}

But that's kinda annoying and I think it would be better if it could be solved somehow by adding some annotation above the table in one place.

Thanks

CppCXY commented 2 years ago

Ok, I will fix that this weekend