LuaLS / LuaLS/lua-language-server
Properties (getter/setter) support
还没有人认领这个 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?
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先从 hoge.meta.lua 和 main.lua 中的注解示例开始,然后重现将一个表赋值给 hoge.position 时的诊断。该 issue 未指明任何仓库文件或测试,因此必须找到相关的注解和类型检查入口。完成的标准是:注解语法可以表达不同的 setter 和 getter 类型,并且示例赋值不再报告缺少 Point 字段。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 30/100