LuaLS / LuaLS/lua-language-server
Proposal: Add @constructor Tag for Class Constructors in Lua LSP
还没有人认领这个 Issue。
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
This Lua LSP could benefit from a new @constructor tag, which would be used when defining classes, especially with libraries. Currently, we have to do something like this:
---@class myCls
---@overload fun(a: integer, b: integer): myCls
local myCls = class "myCls"
---@param a integer
---@param b integer
function myCls:__init(a, b)
self.a = a
self.b = b
end
local instance = myCls(10, 20)
print(instance)
As you can see, we need to create an overload for the variable, which makes the typing process quite repetitive. To address this, we could introduce a new @constructor tag that would automatically handle this:
---@class myCls
local myCls = class "myCls" -- No need for an overload anymore.
-- Defining this method as the constructor:
---@constructor
---@param a integer
---@param b integer
function myCls:__init(a, b)
self.a = a
self.b = b
end
local instance = myCls(10, 20) -- Type checking would work correctly and show the constructor parameters.
print(instance)
This approach would make the code cleaner and more intuitive, reducing the need for repetitive annotations and improving the overall developer experience.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先根据此 issue 中的示例检查现有的 @class 和 @overload 行为;未指定文件、测试或入口点。完成的标准应是:使用 @constructor 标记 init 后,能够为 myCls(10, 20) 这样的调用提供构造函数参数,而无需单独的 overload。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100