LuaLS / LuaLS/lua-language-server

feature: Variadic generic packs and mapping expansion

未關閉
#2,470 0 則留言 4 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
Lua
星號
4.4k
分支
442
PR 合併指標
30 天內沒有已合併 PR

描述

#1861

This feature request requests variadic generics functionality, as well as mapping those generics. My proposed implementation of this feature request would allow the following example syntax:
```lua
---@generic R, T...
---@param fn fun(...: T...):R
---@param ... Component
---@return System
function System.new(fn, ...)
...
end

---@generic R
---@param System self
---@param entities Entity[]
---@return R[]
function System:run()
...
end
```

The example code above also introduces a shorthand for variadics (line 3): whenever the parameter `...` would have an unexpanded parameter pack as an argument, it is implicitly expanded. Any type can be expanded at any point by suffixing a `...`, as shown in line 2.

The motivation of this request arises from an well-typed ECS implementation with object-oriented systems. Without variadic generics, it is not possible in any way I know of to allow a system to depend on any amount of components and still have well-typed parameters.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從相關 issue #1861 以及本 issue 中提出的 Lua 範例開始。定義可變參數泛型包、映射展開和 `...` 簡寫應如何運作,然後驗證所示範的 System API 是否能夠表達具型別的元件參數和回傳值。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
lua
領域
devtools
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。