LuaLS / LuaLS/lua-language-server
Nested Table Type Narrowing
還沒有人認領這個 Issue。
- 主要語言
- Lua
- 星號
- 4.4k
- 分支
- 442
- PR 合併指標
- 30 天內沒有已合併 PR
描述
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
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
先重現 issue 中的兩個 Lua 範例,並檢查處理索引存取、型別縮小和欄位補全的 language-server 路徑。完成的標準是:兩個範例都能為 test_field_1 推斷出 string,並提供可能的巢狀表格型別共有的欄位,同時考量相關的類別縮小問題 2217。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- devtools
- Issue 類型
- 功能
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100