LuaLS / LuaLS/lua-language-server
Exact Class with `__index` Assignment Result in Loss of All Class Methods
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, Hover
Expected Behaviour
Method :method and :method2 is shown.
Actual Behaviour
No method is shown.
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
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 provided Lua snippet and inspect the completion and hover behavior for exact classes with a __index assignment. Use the reported difference between exact and non-exact classes as the starting comparison. Done means Foo methods appear for b and self in completion and hover, without requiring the method name to be typed first.
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
- 42/100