LuaLS / LuaLS/lua-language-server

"array-like" table can't be natively annotated as enum

Aperta
#2,435 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Lua
Stelle
4.4k
Fork
442
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Linux

What is the issue affecting?

Annotations, Hover

Expected Behaviour

On hover over action param in my function I'd like to get annotation consistent with already existing annotation that i get if i hover over all in actions.all :

(field) actions.all: {
    [10]: string = "supportAttack",
    [11]: string = "supportDefence",
    [12]: string = "supportBoth",
    [13]: string = "supportAttackPike",
    [14]: string = "supportDefencePike",
    [15]: string = "stanceShieldwall",
    [16]: string = "stanceLastman",
    [17]: string = "stanceBarrage",
    [18]: string = "encamp",
    [19]: string = "uncamp",
    [1]: string = "retreat",
    [20]: string = "destroyCamp",
    [21]: string = "buildFort",
    [22]: string = "demountFort",
    [23]: string = "destroyFort",
    [24]: string = "rest",
    [25]: string = "respire",
    [2]: string = "move",
    [3]: string = "swap",
    [4]: string = "forcedMove",
    [5]: string = "melee",
    [6]: string = "shoot",
    [7]: string = "shoot2",
    [8]: string = "breakthrough",
    [9]: string = "enclosing",
}

Essentially i'd like enum for this array to give the same behavioir as alias like this

---@alias Action
---| '"retreat"'
---| '"move"
---| '"swap"' 
---| '"forcedMove"'
---| '"melee"'
---| '"shoot"'
---| '"shoot2"'
---| '"breakthrough"
---| '"enclosing"'
---| '"supportAttack"'
---| '"supportDefence"'
---| '"supportBoth"'
---| '"supportAttackPike"'
---| '"supportDefencePike"'
---| '"stanceShieldwall"'
---| '"stanceLastman"'
---| '"stanceBarrage"'
---| '"encamp"'
---| '"uncamp"'
---| '"destroyCamp"'
---| '"buildFort"'
---| '"demountFort"'
---| '"destroyFort"'
---| '"rest"'
---| '"respire"'
Actual Behaviour

On hover over action param in my function I get this annotation:

(parameter) action: Action
{
}
Reproduction steps

Consider this minimal code snippet:

local actions = {}

---@enum Action
actions.all = {
  "retreat",
  "move",
  "swap",
  "forcedMove",
  "melee",
  "shoot",
  "shoot2",
  "breakthrough",
  "enclosing",
  "supportAttack",
  "supportDefence",
  "supportBoth",
  "supportAttackPike",
  "supportDefencePike",
  "stanceShieldwall",
  "stanceLastman",
  "stanceBarrage",
  "encamp",
  "uncamp",
  "destroyCamp",
  "buildFort",
  "demountFort",
  "destroyFort",
  "rest",
  "respire",
}

actions.isStance = {stanceShieldwall = true, stanceLastman = true, stanceBarrage = true}

--- @param action Action
--- @return boolean
function actions.IsStance(action)
  return actions.isStance[action]
end
Additional Notes

No response

Log File

No response

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la riproduzione minima in Lua nell’issue e traccia come vengono rappresentati al passaggio del mouse l’annotazione @enum su actions.all e il parametro Action. Confronta questo percorso con il comportamento esistente degli alias. Il lavoro è completato quando passando il mouse sul parametro Action vengono esposti i membri string dell’enum in modo coerente con il risultato del passaggio del mouse su actions.all.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
lua
Ambito
devtools
Tipo di issue
Funzionalità
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.