LuaLS / lua-language-server

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

新版本 #2631

Open Silent-zzz opened 6 months ago

Silent-zzz commented 6 months ago

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Windows

What is the issue affecting?

Other

Expected Behaviour

---@generic T ---@overload fun(name:frame.T):fun(params:table):T

Actual Behaviour

在fun()中class.T好像还是没办法使用 QQ截图20240424091524

Reproduction steps

  1. Go to '...'
  2. Click '...'
  3. See error '...'

Additional Notes

No response

Log File

No response

tomlau10 commented 1 month ago

(估計 #2501 是 duplicate) 我在搜 overload 相關 issue 時找到這個

@overload fun() 目前仍是不支援 generic 的,#2484 增加的 capture 寫法是針對 @param 目前我試出 workaround 是額外寫1段 不會執行的 if 代碼,單純用來 luals 🤔

---@class frame
local frame = {}

---@class frame.button

local newframe = setmetatable({}, {
    __index = frame,
    __call = function (self, name)
        local class = rawget(self, name)
        if class and getmetatable(class) then
            return function(param)
                return frame(class, param)
            end
        end
    end,
})

if false then
    ---@generic T
    ---@param name frame.`T`
    ---@return fun(param: table): T
    ---@diagnostic disable-next-line
    newframe = function (name) end
end

local a = newframe 'button' {
}