LuaLS / LuaLS/lua-language-server

Ability to use specific enum keys as params

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

還沒有人認領這個 Issue。

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

描述

It would be nice to be able to use specific enum keys as params. For example today if you try to do something like this:

```
---@enum TestEnum
TestEnum = {
ONE = 1,
TWO = 2,
THREE = 3,
}

---@param test TestEnum.ONE
local function test(test)
end

test(TestEnum.ONE)
test(1)
```

You will get an error:
```
Cannot assign `integer` to parameter `TestEnum.ONE`.
- `integer` cannot match `TestEnum.ONE`
- Type `integer` cannot match `TestEnum.ONE`
- Type `number` cannot match `TestEnum.ONE`
```

Interestingly lls understands that TestEnum.ONE is a real thing just not that it is equal to TestEnum.ONE or 1. For exmaple if you try this:
```
---@enum TestEnum
TestEnum = {
ONE = 1,
TWO = 2,
THREE = 3,
}

---@param test TestEnum.One
local function test(test)
end

test(TestEnum.ONE)
test(1)
```
You will get an error:
```
---@param test TestEnum.NonEnumValue
```

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

由於 issue 中沒有指定檔案、測試或進入點,因此請先在 lua-language-server 中尋找 enum 型別檢查與參數可指派性的處理。完成的標準是:TestEnum.ONE 可用於 TestEnum.ONE,且其底層值 1 得到一致處理,同時無效的 enum 鍵仍被拒絕。

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

評估

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

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

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