LuaLS / LuaLS/lua-language-server

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

未關閉
#2,883 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

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

Reproduction steps

Test code:

---@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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

重現提供的 Lua 程式碼片段,並檢查具有 __index 指派的 exact 類別的補全和懸停行為。以回報中 exact 類別與 non-exact 類別之間的差異作為比較的起點。當 Foo 方法在 b 和 self 的補全和懸停中出現,且不需要先輸入方法名稱時,即表示完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
lua
領域
devtools
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
42/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。