LuaLS / LuaLS/lua-language-server

Problem with generics

Offen
#911 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

enhancement feat/generic
Vorherrschende Sprache
Lua
Sterne
4.4k
Forks
442
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

I have reported a similar problem before and I understand that it is not simple, but if you solve it, I will be crazy happy!

I'm working on an OOP library and here's a truncated example of the constructor it uses:

---@generic T
---@param t1 T
---@param t2 T
---@return T
function new(t1, t2) end

The first table here is the class from which the instance will inherit, and the second is the additional settings that will be substituted to the instance. So all tables has the same type.

When I call this constructor, the generics work almost correctly - the result of this function has the same type as any argument:

---@class Example1
---@field e1a string
---@field e1b string
local Example1 = {}

---@class Example2
---@field e2a string
---@field e2b string
local Example2 = {}

local e = new(Example1, {}) -- e is Example1
local e = new(Example2, {}) -- e is Example2
local e = new({}, Example1) -- e is Example1
local e = new({}, Example2) -- e is Example2

But the problem is that when I start typing a text between the curly braces in the example above, I get no hints about the class fields. Maybe I'm describing generics wrong? Do you have any idea? Thanks!

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Es wird keine Quelldatei und kein Test genannt. Reproduziere das generische Konstruktorbeispiel im Lua language server und untersuche, wie die Vervollständigung innerhalb der leeren Tabellenargumente abgeleitet wird, wenn das erste Argument Example1 oder Example2 ist. Als erledigt gilt die Aufgabe, wenn die relevanten Klassenfelder in diesen Tabellenliteralen vorgeschlagen werden und dabei der bestehende abgeleitete Ergebnistyp erhalten bleibt.

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
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.