LuaLS / LuaLS/lua-language-server
@field private in @meta file triggers warning even when accessed within the same class
還沒有人認領這個 Issue。
- 主要語言
- 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?
Annotations
Expected Behaviour
When defining a class in a ---@meta file with @field private annotations, the Lua language server warns about accessing those private fields even when they are accessed within the implementation of the same class (just in a separate file). This makes private fields effectively unusable if you're organizing types in meta files.
The language server should not warn about access to @field private fields when they are accessed within the implementation of the class they belong to, even if that implementation is in a separate file.
I think this is by design rather than a bug, so maybe this is a feature request?
Actual Behaviour
Even though I'm accessing the private field in the implementation of that class, I see a warning:
Reproduction steps
- In types.lua (meta file)
---@meta
---@class (exact) ModuleMixin
---@field private __loaded boolean
---@field Load fun(self)
---@field IsLoaded fun(self): boolean
---@field Init fun(self)
- ModuleMixin.lua (implementation)
---@type SmartChat.ModuleMixin
local ModuleMixin = {}
function ModuleMixin:Init()
self.__loaded = false -- <-- LuaLS warns that __loaded is private
end
Additional Notes
I use a @meta file to separate type annotations from implementation, which is common in larger projects. This issue makes it difficult to use private meaningfully unless everything is co-located in the same file, which defeats the purpose of a metadata/type declaration file.
Would it be possible to make private refer to "the class definition context" rather than "the file only"?
Thanks!
Log File
No response
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
使用 types.lua 和 ModuleMixin.lua 範例重現警告,先從 language server 中的 private 欄位診斷開始。追蹤類別宣告及其實作檔案是如何關聯的。當從實作檔案進行存取時不再產生警告,同時其他位置的 private 欄位檢查仍維持不變時,即可視為完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- devtools
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100