LuaLS / LuaLS/lua-language-server

Nested Table Type Narrowing

オープン
#2,218 コメント 4 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

enhancement
主要言語
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

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、issue にある 2 つの Lua の例を再現し、インデックスアクセス、型の絞り込み、フィールド補完を処理する language-server のパスを調査します。完了条件は、両方の例で test_field_1 に対して string を推論し、可能性のあるネストされたテーブル型に共通するフィールドを提示できることです。その際、関連するクラスの絞り込みに関する issue 2217 も考慮します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
lua
領域
devtools
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。