LuaLS / LuaLS/lua-language-server

Question mark optional syntax not supported in fun() declarations

Aperta
#2,385 1 commento 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?

Windows

What is the issue affecting?

Type Checking

Expected Behaviour

Optional value to actually be optional

Actual Behaviour

It's not optional.
image
This code block should show as Human? and throw warnings for not checking nil. If I manually annotate with ---@param man Human? this works as expected.

The class in question:

---@class Command
---@field info string What the command does.
---@field usage string? How to use the command.
---@field alias string[]? Aliases of the command.
---@field canCall (fun(player: Player): boolean)? Function which checks whether a player can call this command.
---@field call fun(player: Player, human: Human?, args: string[]) Calls the command.
---@field autoComplete fun(args: string[])? Function which manipulates arguments when pressing tab in the terminal.
---@field cooldownTime number? How many seconds a player has to wait before using the command again.

I have also tried with human?: Human and human?: Human? but neither way works.

Reproduction steps
  1. Create class with a field with a short form function declaration with an optional value parameter
  2. Attempt to create object of class with that field,
  3. Parameter correctly types, except as not optional.
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 riproducendo l’esempio di campo della classe nell’estensione Visual Studio Code, concentrandoti sulla dichiarazione di funzione in forma breve con un parametro Human nullable. Confrontalo con il caso annotato manualmente ---@param man Human?; è completato quando il parametro viene inferito come opzionale e compaiono gli avvisi sui controlli nil descritti.

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

Valutazione

Stack tecnologico
lua, vscode
Ambito
devtools
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.