LuaLS / LuaLS/lua-language-server

Exact Class with `__index` Assignment Result in Loss of All Class Methods

Open
#2,883 0 comments 0 reactions 0 assignees View on GitHub

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.
gambar

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

file_d%3A_Data_Development_love-11.3-win64_luals-report.log

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.