LuaLS / LuaLS/lua-language-server

Exact Class with `__index` Assignment Result in Loss of All Class Methods

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

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

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

説明

### How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

### Which OS are you using?

Windows

### What is the issue affecting?

Completion, Hover

### Expected Behaviour

Method `:method` and `:method2` is shown.

### Actual Behaviour

No method is shown.
![gambar](https://github.com/user-attachments/assets/60f0495e-7f9d-49c5-a30d-191368a330c6)

### Reproduction steps

Test code:
```lua
---@class (exact) Foo
local Foo = {}
Foo.__index = Foo ---@diagnostic disable-line inject-field

function Foo:method()
end

function Foo:method2(value)
end

---@return Foo
local function foo()
end

local b = foo()
```

Variable `b` has type of `Foo`. However typing `b:` won't show `method` and `method2`. The `self` variable inside `Foo:nethod` and `Foo:method2` will also have same issue if used.

Removing the `(exact)` make it work works as expected. Removing the `__index` assignment also make it works as expected. However, silencing the `__index` inject field with `---@field __index Foo` instead of using `---@diagnostic` still result in same issue.

Hovering to `b` also won't show any of the methods. However hovering to `Foo` works.

### Additional Notes

Typing the method name manually (e.g. `:method2`) will show completion normally and will make `b` show `method2` after it's used once. But only `method2` in that specific case. `method` still not be shown.

### Log File

[file_d%3A_Data_Development_love-11.3-win64_luals-report.log](https://github.com/user-attachments/files/17241460/file_d.3A_Data_Development_love-11.3-win64_luals-report.log)

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

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

はじめの一歩

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

調査の方向性

提供された Lua スニペットを再現し、__index の代入がある exact クラスについて、補完とホバーの動作を調査します。比較の出発点として、報告された exact クラスと non-exact クラスの違いを使用します。b と self に対して Foo のメソッドが補完とホバーに表示され、最初にメソッド名を入力する必要がなければ完了です。

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

評価

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

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

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