LuaLS / LuaLS/lua-language-server

Nested Table Type Narrowing

Abierto
#2,218 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

enhancement
Lenguaje dominante
Lua
Estrellas
4.4k
Forks
442
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza reproduciendo los dos ejemplos de Lua del issue e inspecciona las rutas del language-server que gestionan el acceso indexado, el estrechamiento de tipos y la compleción de campos. Se considera terminado cuando ambos ejemplos infieren string para test_field_1 y ofrecen los campos compartidos por los posibles tipos de tabla anidados, teniendo en cuenta el problema relacionado de estrechamiento de clases 2217.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
lua
Área
devtools
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.