LuaLS / LuaLS/lua-language-server

Nested Table Type Narrowing

Aperta
#2,218 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

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

Descrizione

It would be super nice to be able to get field suggestions when narrowing an indice of a nested table.

Currently this:

---@class TestClass
---@field test_group_a TestGroupA
---@field test_group_b TestGroupB

---@class TestGroupA : TestGroupCommon
---@field test_field_1 string
---@field test_field_2 string

---@class TestGroupB : TestGroupCommon
---@field test_field_1 string
---@field test_field_3 string

---@class TestGroupCommon
---@field test_field_common string

---@type TestClass
local test_class

---@type 'test_group_a' | 'test_group_b'
local test_group

local test1 = test_class[test_group].test_field_1


---------------------------------------

---@alias TestTable {test_group_a: {test_field_1: string, test_field_2: string}, test_group_b: {test_field_1: string, test_field_3: string}}

---@type TestTable
local test_table

---@type "test_group_a" | "test_group_b"
local test_table_group

local test2 = test_table[test_table_group].test_field_1

The inferred type for test1 and test2 are both unknown. It would be nice if for test1 and test2 the inferred type would be string (as test_field_1 is a string for both, if test_field_1 and test_field_2 differed the inferred the type should be test_field_1_type | test_field_2_type). It would also be nice if on local test1 = test_class[test_group]. there were field suggestions for test_field_1 and test_field_common which are on both TestGroupA and TestGroupB.

Note: to add this for classes would also require doing: https://github.com/LuaLS/lua-language-server/issues/2217

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 i due esempi Lua dell’issue e ispeziona i percorsi del language-server che gestiscono l’accesso indicizzato, il restringimento dei tipi e il completamento dei campi. Il lavoro è completato quando entrambi gli esempi inferiscono string per test_field_1 e offrono i campi condivisi dai possibili tipi di tabella annidati, tenendo conto del problema correlato del restringimento delle classi 2217.

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.