LuaLS / LuaLS/lua-language-server
Proposal: Add @constructor Tag for Class Constructors in Lua LSP
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
This Lua LSP could benefit from a new @constructor tag, which would be used when defining classes, especially with libraries. Currently, we have to do something like this:
---@class myCls
---@overload fun(a: integer, b: integer): myCls
local myCls = class "myCls"
---@param a integer
---@param b integer
function myCls:__init(a, b)
self.a = a
self.b = b
end
local instance = myCls(10, 20)
print(instance)
As you can see, we need to create an overload for the variable, which makes the typing process quite repetitive. To address this, we could introduce a new @constructor tag that would automatically handle this:
---@class myCls
local myCls = class "myCls" -- No need for an overload anymore.
-- Defining this method as the constructor:
---@constructor
---@param a integer
---@param b integer
function myCls:__init(a, b)
self.a = a
self.b = b
end
local instance = myCls(10, 20) -- Type checking would work correctly and show the constructor parameters.
print(instance)
This approach would make the code cleaner and more intuitive, reducing the need for repetitive annotations and improving the overall developer experience.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia esaminando il comportamento esistente di @class e @overload in base agli esempi di questa issue; non vengono indicati file, test o punti di ingresso. Il lavoro dovrebbe considerarsi completato quando contrassegnare init con @constructor fornisce i parametri del costruttore per chiamate come myCls(10, 20), senza richiedere un overload separato.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- lua
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 25/100