lua-language-server
lua-language-server copied to clipboard
Exact Class with `__index` Assignment Result in Loss of All Class Methods
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.