LuaLS / LuaLS/lua-language-server
Nested Table Type Narrowing
Personne n'a encore pris cette issue.
- Langage dominant
- Lua
- Étoiles
- 4.4k
- Forks
- 442
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par reproduire les deux exemples Lua de l’issue et examinez les chemins du language-server qui gèrent l’accès indexé, le rétrécissement des types et la complétion des champs. Le travail est terminé lorsque les deux exemples infèrent string pour test_field_1 et proposent les champs communs aux types de tables imbriquées possibles, tout en tenant compte du problème connexe de rétrécissement de classe 2217.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- lua
- Domaine
- devtools
- Type d'issue
- Fonctionnalité
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100