LuaLS / LuaLS/lua-language-server
Class generics produce unusable and wrong union types
まだ誰も着手していません。
- 主要言語
- Lua
- スター
- 4.4k
- フォーク
- 442
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
### How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
### Which OS are you using?
MacOS, Windows
### What is the issue affecting?
Completion
### Expected Behaviour
Methods `Peek,Push,Pop` have proper type hints
### Actual Behaviour
While types of `a, b, c` are correct the
type hints of methods are unusable with unnecessary union types.
**If `Push` is removed from superclass, then type hints go to normal without unions but still with `` in many places**
```lua
local _lua_setmetatable = setmetatable
Stack = {}
--- @generic T
--- @class Stack : {
--- Pop: (fun(self: Stack): T),
--- Peek: (fun(self: Stack): T),
--- Push: (fun(self: Stack, value: T): Stack),
--- }
--- @field protected _stack any[]
--- @field protected _count integer
Stack.__index = {}
--- Creates a new, empty stack.
--- @generic T
--- @return Stack
function Stack.New()
local this = {
_stack = {},
_count = 0,
}
return _lua_setmetatable(this, Stack)
end
local st = Stack.New() --[[@as Stack<{ num: integer }>]]
local a = st:Peek()
local b = st:Pop()
local c = st:Push({})
```
### Reproduction steps
Analyze specified code in VSCode with luals installed
### Additional Notes
_No response_
### Log File
_No response_
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
lua-language-serverをインストールした状態でVS CodeのLuaスニペットを分析し、Stack.NewとPeek、Pop、Pushメソッドの補完ヒントに重点を置いて問題を再現します。a、b、cの推論された型を、期待される非ユニオン型のメソッドヒントと比較します。メソッドに使用できない、または不要なユニオン型や、余分なジェネリックプレースホルダーが表示されなくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100