LuaLS / LuaLS/lua-language-server

Defining table fields of a class across multiple files breaks auto-complete

未关闭
#2,313 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

### Expected Behaviour

If we have a class such as:
```lua
---@class MyClass
MyClass = {
SomeTable = {
A = "Something",
},
}
```
Then another definition of it in another file (an "extension" of the class):
```lua

-- This file extends the MyClass class.

---@class MyClass
local MyClass = MyClass

MyClass.SomeTable.B = "Other thing"
```
Trying to access `MyClass.SomeTable` should show both `A` and `B` as options in auto-complete.

### Actual Behaviour

If the keys of a table within a class are defined across multiple files, auto-complete will not work for them all. If you access these keys however, the hover tooltip will be correct and go-to-definition will work.

![image](https://github.com/LuaLS/lua-language-server/assets/53646914/4787fda5-9894-4e42-a527-f6303379e95f)

This is best understood with an example folder. I've attached it below and its code is also shown in the reproduction steps.

### Reproduction steps

If you have a class definition in one file such as:
`Class_Main.lua`:
```lua

---@class MyClass
MyClass = {
SomeTable = {
A = "Something",
},
}
```
And you try to add keys to `SomeTable` in another file such as:
`Class_Extensions.lua`
```lua

-- This file extends the MyClass class.

---@class MyClass
local MyClass = MyClass

MyClass.SomeTable.B = "Other thing"
```

Then trying to access `Class.SomeTable.` in another file **will not** show `B` as an option in auto-complete. `B` will only show in auto-complete in the file were it was added, despite `Class` there being tagged with `@class` - which I would expect to add `B` to the class definition and not just the local usage of it.

`UserCode.lua`:
![image](https://github.com/LuaLS/lua-language-server/assets/53646914/4787fda5-9894-4e42-a527-f6303379e95f)

As mentioned previously, if you do access `B` by typing it manually, the hover tooltip will be correct and Ctrl+Click to go to definition will work as expected.

![image](https://github.com/LuaLS/lua-language-server/assets/53646914/dfe61fd5-2c3b-4464-ac9b-6534c346f075)

### Additional Notes

Example folder replicating the issue is attached. It's the same example as the one shown above.
[LLS_ClassExtensionBug.zip](https://github.com/LuaLS/lua-language-server/files/12551065/LLS_ClassExtensionBug.zip)

### Log File

_No response_

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

在 Visual Studio Code 扩展中,使用报告或附带示例中的 Class_Main.lua、Class_Extensions.lua 和 UserCode.lua 重现该问题。首先跟踪跨文件对 MyClass.SomeTable 的补全,并将其与已经正常工作的悬停和转到定义行为进行比较。当从另一个文件访问该表时,补全同时列出 A 和 B,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
lua
领域
devtools
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。