Replies: 2 comments
-
Same problem here. I tried to workaround this by definining a global class function for LuaLS in the type definition which emulates luabind's class function like this: ---Luabind "class" emulation in plain Lua.<br>
---Returns a callable table to set the base class.
---
---See [Luabind class](https://luabind.sourceforge.net/docs.html#class_lua)<br>
---@param name string
function class(name)
-- globally register the new class as table with the given name
local class_table = {}
_G[name] = class_table -- NB: use 'rawset' in strict mode
-- override class table's call operator to use the class name as constructor too
setmetatable(class_table, {
__call = function(self, ...)
-- create a new instance of the class
local new_object = {}
setmetatable(new_object, {
__index = class_table,
})
-- call new class' __init function, when its present
if rawget(class_table, "__init") then
class_table.__init(new_object, ...)
end
return new_object
end
})
-- return a callable table which optionally sets a base class
return setmetatable({}, {
__call = function(self, base)
for k, v in pairs(base) do
class_table[k] = v
end
end
})
end Unfortunately LuaLS does not pick up the So this is still needed to make the class and constructor function visible: ---@class Base
---@operator call: Base
Base = {}
class "Base"
---@class Derived: Base
---@operator call: Derived
Derived = {}
class "Derived" (Base) Ideally it would be just: ---@class Derived: Base
class "Derived" (Base) |
Beta Was this translation helpful? Give feedback.
-
Ended up in writing a simple plugin for this, which automatically adds: ---@class Derived: Base
Derived = {} for statements like: class "Derived" (Base) The plugin is here: https://github.com/renoise/definitions/blob/main/plugin.lua |
Beta Was this translation helpful? Give feedback.
-
We use
class
function from luabind api to define classes in lua files.Meta annotation for
class
function look like this:Language server reports on that kind of classes
Undefined global `Test`.Lua Diagnostics.(undefined-global)
To fix the problem we try to explicitly define table :
This workaround adds annoying job and works partly. Because luabind generate extra methods for the table, that also good to be anotated.
How to annotate
class
function that it help to language server to define class for annotation engine. Is possible to use@generic
in function to do that?Beta Was this translation helpful? Give feedback.
All reactions