LuaLS / lua-language-server

A language server that offers Lua language support - programmed in Lua
https://luals.github.io
MIT License
3.38k stars 319 forks source link

Exact Classes Do Not Autocomplete Methods #2919

Open alex-courtis opened 3 weeks ago

alex-courtis commented 3 weeks ago

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 commented 3 weeks ago

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 https://github.com/LuaLS/lua-language-server/pull/2841 by @Luke100000 🤔

alex-courtis commented 3 weeks ago

Legend! Many thanks for your digging.

MikuAuahDark commented 2 weeks ago

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.