LuaLS / LuaLS/lua-language-server

Register function environment variables

未關閉
#15 5 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

enhancement feat/LuaCats Annotations priority.normal
主要語言
Lua
星號
4.4k
分支
442
PR 合併指標
30 天內沒有已合併 PR

描述

This extension is able to detect usage of undefined global variables:
image

However, setfenv is used on this function to define the missing variable, but at another point in the code that the parser can't detect. Is it possible to somehow tell the parser to ignore this diagnostic? Something like:

local block = function(_)
    -- env: {block, assert, error}
    block()
end

Then it would accept those values? I know you can define globals for the project, but this doesn't affect the entire project, only those functions, so it would be cool if you could define it somehow.

Alternatively, could we just disable the diagnostic?

local block = function(_)
    -- disable: undefined-global
    block()
end

I don't know if the parser supports reading comments like that, let me know if that won't work or if you have better ideas for it.

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

首先追蹤 parser 的未定義全域變數診斷,以及它如何讀取專案層級的全域定義。評估 issue 中提出的函式區域環境註解和停用診斷的註解,然後確認所選語法只會抑制或解決預期的函式範圍警告。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
lua
領域
devtools
Issue 類型
功能
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。