LuaLS / LuaLS/lua-language-server
Problem with generics
まだ誰も着手していません。
- 主要言語
- Lua
- スター
- 4.4k
- フォーク
- 442
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
I have reported a similar problem before and I understand that it is not simple, but if you solve it, I will be crazy happy!
I'm working on an OOP library and here's a truncated example of the constructor it uses:
---@generic T
---@param t1 T
---@param t2 T
---@return T
function new(t1, t2) end
The first table here is the class from which the instance will inherit, and the second is the additional settings that will be substituted to the instance. So all tables has the same type.
When I call this constructor, the generics work almost correctly - the result of this function has the same type as any argument:
---@class Example1
---@field e1a string
---@field e1b string
local Example1 = {}
---@class Example2
---@field e2a string
---@field e2b string
local Example2 = {}
local e = new(Example1, {}) -- e is Example1
local e = new(Example2, {}) -- e is Example2
local e = new({}, Example1) -- e is Example1
local e = new({}, Example2) -- e is Example2
But the problem is that when I start typing a text between the curly braces in the example above, I get no hints about the class fields. Maybe I'm describing generics wrong? Do you have any idea? Thanks!
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
ソースファイルもテストも指定されていません。Lua language server にあるジェネリックコンストラクターの例を再現し、最初の引数が Example1 または Example2 の場合に、空のテーブル引数内で補完がどのように推論されるかを調べてください。これらのテーブルリテラルで関連するクラスフィールドが提案され、既存の推論結果型が維持されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100