LuaLS / LuaLS/lua-language-server

Properties (getter/setter) support

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

還沒有人認領這個 Issue。

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

描述

Lua's variables can act as C#-like properties by setting `__newindex` appropriately.

Getters and setters occasionally have different type signatures. However, the `@field` annotation can only represent one type.

```lua
-- hoge.meta.lua

---@meta

---@class Point
---@field x number
---@field y number
Point = {}

---@class Hoge
---@field position Point ⚠️ actually a property
Hoge = {}

---@return Hoge
function new_hoge() end
```

```lua
-- main.lua

local hoge = new_hoge()
hoge.position = { 3, 7 } -- emits "Missing required fields in type `Point`: `x`, `y`"
print(hoge.position.x) -- 3.0
print(hoge.position.y) -- 7.0
```

(Full sample program is [here](https://codeberg.org/haruomaki/luaproperty))

It should be annotated as "`position`'s setter receives a `table`, and its getter returns a `Point`."

How about adding a new syntax to describe this?

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

先從 hoge.meta.lua 和 main.lua 中的註解範例開始,然後重現將一個表格指派給 hoge.position 時的診斷。該 issue 未指定任何儲存庫檔案或測試,因此必須找到相關的註解和型別檢查進入點。完成的標準是:註解語法可以表達不同的 setter 和 getter 型別,而且範例指派不再回報缺少 Point 欄位。

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

評估

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

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

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