LuaLS / LuaLS/lua-language-server
Better global recognizing for loadfile
還沒有人認領這個 Issue。
- 主要語言
- Lua
- 星號
- 4.4k
- 分支
- 442
- PR 合併指標
- 30 天內沒有已合併 PR
描述
In some cases you might need to make the plugin recognize a specific local variable as global, without declaring that variable as an actual global, one of these cases are using load and loadfile were you can pass an env variable that represents the chunk environment.
*mainFile.lua
local env = setmetatable(
{foo = function(a, b) return a == b end},
{__index = _G}
)
loadfile('./secondFile.lua', 't', env)
*secondFile.lua
foo(1, 2) -- Undefined global `foo` . Lua Diagnostics.(undefined-global)
So i would suggest better recognizing for load/loadfile/loadstring environment or/and a custom emmylua annotations --- @global that marks the local var as a global one.
Thanks in advance.
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先追蹤語言伺服器如何回報 undefined-global 診斷,以及它如何處理 load、loadfile 和 loadstring 環境。將該行為與 mainFile.lua 和 secondFile.lua 範例進行比較,接著判斷環境辨識或 @global 註解是否才是預期的範圍。完成的標準是:在選定的行為下,該範例不再將 foo 回報為未定義。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- devtools
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 25/100