LuaLS / LuaLS/lua-language-server

Template Annotation

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

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

question
主要言語
Lua
スター
4.4k
フォーク
442
PR マージ指標
30日以内にマージされた PR はありません

説明

I love the new missing-fields diagnostic! It is super helpful to guarantee safety especially for function arguments (though its usefullness in my repo has stagnated slightly due to https://github.com/LuaLS/lua-language-server/issues/2214)

However, it does come into conflict with something I do in a few places where I specifically set a type annotation for the autocomplete where the data in the table is initialized later in a meta_table (or the data is only every accessible through the meta_table).

---@type WeaponsUnitData
Weapons.unit = {}

setmetatable(Weapons.unit, Metatable.unit_metatable())

With the new missing-fields diagnostic I get a warning here, that Weapons.unit doesn't contain all of the fields on WeaponsUnitData. I was wondering with the missing-fields diagnostic we could get a ---@template annotation which could describe the shape of a table without having to define all of the fields on it. (As a cleaner alternative to having to do ---@diagnostic disable-next-line: missing-fields in a bunch of places). I am sure other people were also using tables in other weird ways before as well, this would allow an easy transition for them.

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

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

はじめの一歩

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

調査の方向性

既存の missing-fields 診断と、---@type に関係するアノテーション処理から始めます。すべてのフィールドを必須にせずに ---@template アノテーションでテーブルの形状を記述する方法を検討し、次に Weapons.unit を使用する例で警告が生成されなくなり、通常の欠落フィールドチェックは引き続き維持されることを確認します。

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

評価

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

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

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