LuaLS / LuaLS/lua-language-server

---@class with function return question

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

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

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

説明

so I have this (as a mockup):
```lua
do
---@class a
local a = {}

---@generic T
---@param self a
---@param new T
---@return T
a.extend = function(self, new)
--...
return new
end
end
```
and it's supposed to be inheritance for prototypes, right, but I'm trying to make the LS think that it returns the second parameter `new` and it does that and the LS thinks that, so far so good. So this
```lua
local b = a:extend{
n = 1
}
```
will make it like this:
![p1](https://github.com/LuaLS/lua-language-server/assets/50140319/ae40c16c-62bd-4429-8c40-1c2d5190d446)
but the problem is, that if I use `---@class b` here, then it will ignore what the function returns and I get this:
![p2](https://github.com/LuaLS/lua-language-server/assets/50140319/b0535d12-35f5-49cc-8088-2ae955b32f4a)
am I missing something or is it just not possible? Though, if I separate it into two statements like this,
```lua
---@class b
local b = {
n = 1
}

b = a:extend(b)
```
then I get what I want:
![p3](https://github.com/LuaLS/lua-language-server/assets/50140319/d56f304d-8fef-46c6-baa8-45491c2829d2)
but it's not ideal, since it's two statements now and I can't use the `fun{}` syntactic sugar this way, which would be the whole reason, right. Is there a way to make it work? Also I'm unsure about how to properly word the title here

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

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

はじめの一歩

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

調査の方向性

ソースファイルやテストは指定されていません。1行のLuaスニペット2つと、2文のLuaスニペット2つを再現し、その後、ローカル宣言、クラスアノテーション、ジェネリクス、関数の戻り値に対するLuaLSの型推論を追跡してください。対応する動作が実装され、回帰テストでカバーされているか、制限事項が明確にドキュメント化されていれば完了です。

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

評価

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

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

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