Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Exact Classes Do Not Autocomplete Methods #2919

Open
alex-courtis opened this issue Oct 28, 2024 · 3 comments
Open

Exact Classes Do Not Autocomplete Methods #2919

alex-courtis opened this issue Oct 28, 2024 · 3 comments

Comments

@alex-courtis
Copy link

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Linux

What is the issue affecting?

Completion

Expected Behaviour

Autocomplete should complete methods on instances of (exact) classes.

Expected completion for a normal class:
20241029_094227

Actual Behaviour

Methods are not completed.

20241029_094211

Reproduction steps

VSCode project with v3.11.0 plugin.

All defaults, no .luarc.json.

Ctrl-space at last line.

---@class (exact) Point
--@class Point
---@field x number
---@field y number
local Point = {}

function Point:new(o)
  o = o or {}

  setmetatable(o, self)
  self.__index = self ---@diagnostic disable-line: inject-field

  return o
end

---@param i integer
function Point:add(i)
  self.x = self.x + i
end

---@type Point
local point = Point:new({ x = 1, y = 2 })

point:

Additional Notes

Many thanks for all the fantastic work - luals makes me so much more productive!

Log File

log.tar.gz

@tomlau10
Copy link
Contributor

tomlau10 commented Oct 29, 2024

I tried to checkout an older stable version of luals: v3.9.3, and seems it works at that version.
So maybe something related to exact class is broken in recent changes 😕


Then I performed a git bisect, and I found this issue started to occur from the following commit:

5f07b7efa6db1027a7fac64c31d7f8663dfc7d34 is the first bad commit
commit 5f07b7efa6db1027a7fac64c31d7f8663dfc7d34
Author: Luke100000 <jonas.peche@aon.at>
Date:   Tue Mar 19 09:49:33 2024 +0100

    exact classes no longer use local field defs

 script/vm/compiler.lua | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

That is #2841 by @Luke100000 🤔

@alex-courtis
Copy link
Author

Legend! Many thanks for your digging.

@MikuAuahDark
Copy link

I opened #2883 a while back and I mentioned that if the __index assignment is removed, it will work as expected. The current behavior is definitely broken though.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants