LuaLS / LuaLS/lua-language-server
@field private in @meta file triggers warning even when accessed within the same class
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Lua
- Sterne
- 4.4k
- Forks
- 442
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduziere die Warnung anhand der Beispiele types.lua und ModuleMixin.lua, beginnend mit der Diagnose für private Felder im language server. Verfolge, wie die Klassendeklaration und ihre Implementierungsdatei miteinander verknüpft werden. Als erledigt gilt die Aufgabe, wenn Zugriffe aus der Implementierung keine Warnungen mehr auslösen, während Prüfungen privater Felder an anderer Stelle intakt bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- lua
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100