LuaLS / LuaLS/lua-language-server
Defining table fields of a class across multiple files breaks auto-complete
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
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:
---@class MyClass
MyClass = {
SomeTable = {
A = "Something",
},
}
Then another definition of it in another file (an "extension" of the class):
-- 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.
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:
---@class MyClass
MyClass = {
SomeTable = {
A = "Something",
},
}
And you try to add keys to SomeTable in another file such as:
Class_Extensions.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:
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.
Additional Notes
Example folder replicating the issue is attached. It's the same example as the one shown above.
LLS_ClassExtensionBug.zip
Log File
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue using Class_Main.lua, Class_Extensions.lua, and UserCode.lua from the report or attached example in the Visual Studio Code extension. Start by tracing completion for MyClass.SomeTable across the files, comparing it with the already-working hover and go-to-definition behavior. Done means completion lists both A and B when the table is accessed from another file.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100