Open Mayron opened 1 year ago
I suggest you modify your code:
function ParentTable:_Execute(data, hello, world)
-- data is a special parameter controlled by the metatable and is given a table value
-- hello is assigned "hello" and world is assigned "world"
end
function ParentTable:Execute(hello, world)
self:_Execute(self._data, hello, world)
end
@sumneko Unfortunately I can't do that because the data
table is supposed to be for private data (it's a strict object-oriented framework) so that would make it public and accessible to outside code.
Also, the user could see data
as a possible argument option if they're using LuaLS. I don't want it showing in editors like VS Code as that might confuse the users using the framework.
I can at least use @overload fun(self: ParentTable, hello: string, world: string)
to hopefully prevent the linter from complaining when data
is omitted (as it should be to work with the framework), but it only adds a 2nd way of using the method and I can't hide the default implementation.
I don't think the annotation should limit and dictate how the programming language should be used. If I can do this in Lua then I shouldn't need to tell the author of the OOP framework I'm using to change its behaviour to work with linting tools, ideally.
LuaLS has private
and protected
features designed to hide certain things already so it's not too different to be able to control what we want to show for function notations by overriding the default implementation. What do you think?
Preferably, I'd like to write something like @param hidden data table
to say "data is a table but it should not be shown when hovering over the function in an editor". Or a way of completely overriding the default signature but that seems more complex as it would need to ignore other annotations if used together with @param
and @return
etc...
That could look like this: ---@default fun(self: ParentTable, hello: string, world: string)
I have a table with a metatable assigned to it to implement inheritance. The metatable's
__index
metamethod intercepts a call to a function on the original table and gets the actual function from the "parent" table and then injects another parameter into the function call.For example, the user would call the function like this:
tbl:Execute("hello", "world")
and the function would be implemented like this:The problem with this is that VS Code and LuaLS warns the user that they didn't provide a value to
data
. I have to use@overload
to every single method to say you can call this method with just "hello" and "world" arguments provided.I want to be able to tell LuaLS to completely hide/ignore the
data
parameter and pretend it doesn't exist; essentially moving all other parameter indexes down by 1 to fill the empty spot, so "hello" is recognized as parameter 1 and "world" as parameter 2.