LuaLS / LuaLS/lua-language-server

Properties (getter/setter) support

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

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

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

説明

Lua's variables can act as C#-like properties by setting `__newindex` appropriately.

Getters and setters occasionally have different type signatures. However, the `@field` annotation can only represent one type.

```lua
-- hoge.meta.lua

---@meta

---@class Point
---@field x number
---@field y number
Point = {}

---@class Hoge
---@field position Point ⚠️ actually a property
Hoge = {}

---@return Hoge
function new_hoge() end
```

```lua
-- main.lua

local hoge = new_hoge()
hoge.position = { 3, 7 } -- emits "Missing required fields in type `Point`: `x`, `y`"
print(hoge.position.x) -- 3.0
print(hoge.position.y) -- 7.0
```

(Full sample program is [here](https://codeberg.org/haruomaki/luaproperty))

It should be annotated as "`position`'s setter receives a `table`, and its getter returns a `Point`."

How about adding a new syntax to describe this?

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

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

はじめの一歩

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

調査の方向性

hoge.meta.lua と main.lua のアノテーション例から始め、次にテーブルを hoge.position に代入したときの診断を再現します。この issue ではリポジトリのファイルやテストが指定されていないため、関連するアノテーションおよび型チェックのエントリポイントを特定する必要があります。アノテーション構文で setter と getter に異なる型を表現でき、サンプルの代入で Point のフィールドが不足しているという報告が出なくなれば完了です。

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

評価

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

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

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