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

新版本

Open Silent-zzz opened this issue 1 year ago • 1 comments

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

Silent-zzz avatar Apr 24 '24 01:04 Silent-zzz

(估計 #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' {
}
  • 這樣能將帶 generic 的 function type union 到 newframe variable 之中

tomlau10 avatar Sep 07 '24 10:09 tomlau10