LuaLS / LuaLS/lua-language-server
Proposal: Add @constructor Tag for Class Constructors in Lua LSP
まだ誰も着手していません。
- 主要言語
- 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 にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、この issue の例に照らして既存の @class と @overload の動作を確認してください。ファイル、テスト、エントリーポイントは指定されていません。init に @constructor を付けることで、別個の overload を必要とせず、myCls(10, 20) のような呼び出しにコンストラクターのパラメーターが提供されれば、完了とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100