Is there any way to get intelligent object oriented autocompletion in scripts?

For example, if I define a class in modulescript A, and required it in script B, and used a .new() method that I defined to instantiate the object defined in A, is it possible to get autocompletion for this instantiated object?

1 Like

The current autocomplete we have in the scripter editor might cover these objects to a certain extent, but other than that, there is no way to get customized autocomplete results.

Would be neat to have in the future though.

4 Likes

Intellisense is hardcoded C side.

Although with the new API dump in JSON feature, it might be a good idea to place a dump file in the install directory, let devs mess with the JSON, and have intellisense work off that file’s contents.

It’s possible but not implemented now. Roblox’s Intellisense right now sees the return value of require([module]) as an unknown type instead of digging deep to infer what the module is actually returning. So it doesn’t know if your module is returning a table, a string, a number, etc.

1 Like

It does, actually. If it’s a table, it shows autocomplete for the children.

image

1 Like

Ah, I see. It wasn’t giving me that autocomplete because I always use WaitForChilds to get to the path of a module.

1 Like

Same here, I always use WaitForChild just in case, but mainly because the module isn’t a child of the script. This is interesting to know, though. Could have it not use WaitForChild while scripting but before publishing change it to use WaitForChild.

I also made a feature request that would solve this: Intellisense WaitForChild typing

2 Likes

Can we ditto that for all types of FindFirstChild?

If you’re using the metatable-based OOP pattern, such as this:

local Vector1 = {}
Vector1.__index = Vector1

function Vector1.new(x)
    local self = {
        x = x,
    }
    -- N.B. autocomplete cannot peer into the return value of setmetatable(), use it in a side effecting fashion like this
    setmetatable(self, Vector1)
    return self
end

-- static function
function Vector1.fromPolarCoordinates(distance)
    return Vector1.new(distance)
end

function Vector1:dot(other)
    return self.x * other.x
end

return Vector1

Then autocomplete will currently be able to complete:

  • Vector1.new()
  • Vector1.fromPolarCoordinates
  • myVector1.x

But not:

  • myVector1:dot(otherVector1)
5 Likes