LuaLS / LuaLS/lua-language-server
When defining global variable using `---@class _G` + `---@field`, no autocompletion in `_G.*` for those injected fields
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?
Completion
Expected Behaviour
The _G class is defined in extension's basic.lua, representing the global vairable. I expected the following should merge the defined fields into the global variable.
---@class _G
---@field player_min integer
---@field player_max integer
print(p--[[should have autocompletion]])
print(_G.p--[[should have autocompletion]])
Actual Behaviour
LuaLs recognized the injected field in the hover preview of _G, however no autocompletion for those fields are provided, unless I write _G._G.*.
---@class _G
---@field player_min integer
---@field player_max integer
print(p--[[no autocompletion]])
print(_G.p--[[no autocompletion]])
print(_G._G.p--[[!!! has autocompletion !!!]])
Reproduction steps
Use the code snippet provided above.
Additional Notes
LuaLS actually recognized the injected fields in the hover preview of _G, just the autocompletion is not working as expected.
Meanwhile the workaround is the use ---@type annotation for global variable. However as discussed here, unless the global variable is of table type, otherwise any default value assigned to it will be misleading as the global variable may not be a const.
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 das Vervollständigungsverhalten in der Visual Studio Code-Erweiterung mithilfe des bereitgestellten Lua-Snippets und untersuche anschließend die basic.lua-Definition für _G sowie den Vervollständigungspfad. Als abgeschlossen gilt die Aufgabe, wenn mit @field deklarierte Felder auf _G sowohl in der globalen Vervollständigung als auch in der _G.-Vervollständigung erscheinen, ohne dass _G._G. erforderlich ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- lua
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100