LuaLS / LuaLS/lua-language-server

`@overload` does not cooperate with `@class` when adding overloads to an inherited class method

未關閉
#3,364 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

主要語言
Lua
星號
4.4k
分支
442
PR 合併指標
30 天內沒有已合併 PR

描述

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

NeoVim

### Which OS are you using?

Linux

### What is the issue affecting?

Completion

### Expected Behaviour

Adding an overload to a function inherited from another class should result in both the parent class' overloads and the new overload being suggested as autocomplete and hover tooltip entries.

### Actual Behaviour

Adding an overload to a function inherited from another class makes that overload the only one that is recognized for the current class.

### Reproduction steps

```lua
---@meta

---@class ParentClass
ParentClass = {}

---@param arg string
---@return unknown
---@overload fun(self, arg: "bar"): boolean
function ParentClass:foo(arg) end

---@class ChildClass : ParentClass
---@field foo fun(self, arg: "baz"): number
ChildClass = {}

ChildClass:foo(--[[Should suggest both "bar" and "baz", but only suggests "baz" and "bar" raises a param-type-mismatch]])
```
Redefining the function and adding an `@overload` there yields the same result.

### Additional Notes

Having some way to mark a function redefinition as an overload (with strict checking that it does exist in the class defined as inherited from) would probably help solve this issue.

### Log File

_No response_

貢獻指南

開啟貢獻指南

從這裡開始

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

研究方向

從重現中展示的 Lua 註解和補全行為開始,重點關注 @class 繼承和 @overload 宣告的處理方式。在 NeoVim 中重現此情況,並驗證補全和懸停提示都顯示繼承的 "bar" 多載和子類別的 "baz" 多載,且不存在參數型別不相符。

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

評估

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

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

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