LuaLS / LuaLS/lua-language-server
Template Annotation
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Lua
- Sterne
- 4.4k
- Forks
- 442
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
I love the new missing-fields diagnostic! It is super helpful to guarantee safety especially for function arguments (though its usefullness in my repo has stagnated slightly due to https://github.com/LuaLS/lua-language-server/issues/2214)
However, it does come into conflict with something I do in a few places where I specifically set a type annotation for the autocomplete where the data in the table is initialized later in a meta_table (or the data is only every accessible through the meta_table).
---@type WeaponsUnitData
Weapons.unit = {}
setmetatable(Weapons.unit, Metatable.unit_metatable())
With the new missing-fields diagnostic I get a warning here, that Weapons.unit doesn't contain all of the fields on WeaponsUnitData. I was wondering with the missing-fields diagnostic we could get a ---@template annotation which could describe the shape of a table without having to define all of the fields on it. (As a cleaner alternative to having to do ---@diagnostic disable-next-line: missing-fields in a bunch of places). I am sure other people were also using tables in other weird ways before as well, this would allow an easy transition for them.
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
Beginnen Sie mit der vorhandenen Diagnose missing-fields und der bei ---@type relevanten Verarbeitung von Annotationen. Ermitteln Sie, wie eine ---@template-Annotation eine Tabellenstruktur beschreiben könnte, ohne jedes Feld vorauszusetzen, und überprüfen Sie anschließend, dass das Beispiel mit Weapons.unit die Warnung nicht mehr erzeugt, während normale Prüfungen auf fehlende Felder weiterhin intakt bleiben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- lua
- Bereich
- devtools
- Issue-Typ
- Feature
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 30/100