LuaLS / LuaLS/lua-language-server
When defining global variable using `---@class _G` + `---@field`, no autocompletion in `_G.*` for those injected fields
まだ誰も着手していません。
- 主要言語
- 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?
Windows
What is the issue affecting?
Completion
Expected Behaviour
The _G class is defined in extension's basic.lua, representing the global vairable. I expected the following should merge the defined fields into the global variable.
---@class _G
---@field player_min integer
---@field player_max integer
print(p--[[should have autocompletion]])
print(_G.p--[[should have autocompletion]])
Actual Behaviour
LuaLs recognized the injected field in the hover preview of _G, however no autocompletion for those fields are provided, unless I write _G._G.*.
---@class _G
---@field player_min integer
---@field player_max integer
print(p--[[no autocompletion]])
print(_G.p--[[no autocompletion]])
print(_G._G.p--[[!!! has autocompletion !!!]])
Reproduction steps
Use the code snippet provided above.
Additional Notes
LuaLS actually recognized the injected fields in the hover preview of _G, just the autocompletion is not working as expected.
Meanwhile the workaround is the use ---@type annotation for global variable. However as discussed here, unless the global variable is of table type, otherwise any default value assigned to it will be misleading as the global variable may not be a const.
Log File
No response
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された Lua スニペットを使用して Visual Studio Code 拡張機能の補完動作を再現し、その後、_G に対する basic.lua の定義と補完経路を調査します。_G に @field で宣言されたフィールドが、_G._G.* を必要とせずに、グローバル補完と _G.* 補完の両方に表示されれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100