-
-
Notifications
You must be signed in to change notification settings - Fork 390
Description
How are you using the lua-language-server?
NeoVim
Which OS are you using?
Linux
What is the issue affecting?
Completion
Expected Behaviour
When using class.lua from a seemingly popular Hump library for Love2D, LS should autocomplete class methods, e.g.:
-- player.lua
Player = class{}
function Player:init(x, y)
self.x = x
self.y = y
end
function Player:update(dt)
-- [...]
end-- main.lua
class = require('class')
require('player')
p = Player( -- it should autocomplete `Player:init()` params
p: -- ctrl+space after `:` should show `update(dt)`, etc.Actual Behaviour
LS says Player is:
(global) Player: {
init: function,
update: function,
x: any,
y: any,
}...but p is:
(global) p: unknownMy understanding is that p:update(dt) is just a syntactic sugar for p.update(self, dt), so p: should trigger LuaLS to look up methods from the table and the meta table. AFAIU class.lua does some magic with setmetatable() to make that work. The code itself works fine, so Lua interpreter doesn't have issues finding the methods in meta, just LS does.
Reproduction steps
- Go to https://github.com/vrld/hump/blob/master/class.lua - download raw file
- Put it in a fresh project
- Create sample class:
-- player.lua
Player = class{}
function Player:init(x, y)
self.x = x
self.y = y
end
function Player:update(dt)
-- [...]
end- Require both in main:
-- main.lua
class = require('class')
require('player')
p = Player(5, 10)- Try autocompleting methods in main
Additional Notes
I'm new to Lua, and don't understand yet what class.lua does exactly, so it might be that (old) library's fault... especially because the same issue doesn't happen for push.lua (a resolution scaling library for Love2D), but push.lua doesn't try to extend Lua objects.
I wasted 14 hours trying to solve it with AI and all models I tried say it should work. I looked for similar issues, but I only found some about exact class, and IDK what that is yet - if it's the same thing, sorry.
Both, Hump's class.lua and push.lua, are used in Harvard CS50's gamedev courses.
Log File
(it doesn't fit, because it loads Luv library and the entire Neovim's runtime - sorry for that 🙁 that's what the "initial" Neovim's config does, so many Neovim users will have exactly that)