Autocomplete Issues with "self" and OOP
Could be a Bug or Feature request. I don't think this is a bug, because the implementation for what I am specifically asking here, doesn't exist. So it's more of a "Feature request". Can't change the label anymore though.
I will mainly note 2 issues.
The autocomplete is part of this repository, I believe?
local test = {}
test.__index = test
test.value = "hello"
function test.new()
local self = setmetatable({}, test)
return self
end
return test
Let's work with this.
Issue 1 - Fields and Methods interpretation
. and :
Defining the function like so
Successfully gives you :GET as an autocomplete.
However, this doesn't.
And that is Issue 1.
Issue 2 - "self" Inheritance?
self. is unable to autocomplete more.
At least self could be showing all the methods from it's original object, which is test. But it doesn't do that.
One could use export but this is not automatic, so it's annoying.
That's Issue 2.
I mean, self can be seen as any other variable. But it gets highlighted as red. It could get special treatment to do better autocompletion.
The core issue here is that Luau currently takes the very conservative stance that self can only be inferred from the way it is used within each individual method. It is, after all, completely valid to write test.GET(5).
This approach is pretty simple and general, but I agree that it has some pretty unfortunate consequences.
This is something we're looking to improve. Take a look at this RFC for details: https://github.com/luau-lang/rfcs/pull/5
I think I still have a discussion open about AST.