LuaLS / LuaLS/lua-language-server

Proposal: Add @constructor Tag for Class Constructors in Lua LSP

オープン
#3,063 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、この issue の例に照らして既存の @class と @overload の動作を確認してください。ファイル、テスト、エントリーポイントは指定されていません。init に @constructor を付けることで、別個の overload を必要とせず、myCls(10, 20) のような呼び出しにコンストラクターのパラメーターが提供されれば、完了とします。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
lua
領域
devtools
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。