Go To Declaration for metatables

I constantly find myself needing to go to a metatable function but having to manually search for it. It would be great if it could use the typing information to be able to automatically go to the function with the press of a key.

self:someMethod()

Basically you would just have your cursor on someMethod, press the hotkey and it would use the metatable to look that up.

4 Likes

Hi, thanks for the feature request!

In order to parity with other editors (e.g. VSCode editing JavaScript) there’s some behind-the-scenes type technology we’d need. There’s a draft Luau RFC for “shared self types” that would have to land and be implemented, which would make it possible for Studio to get the needed information about metatables to support go-to-declaration. So I’d suggest following RFC for shared self types by asajeffrey · Pull Request #863 · Roblox/luau · GitHub to see where we are in that process.

3 Likes

Here is an example of how I do OOP:

--!strict

local module = {}

export type schema_raw = {
	_test: number,
}
export type schema = typeof(setmetatable({}::schema_raw, {__index=module}))

function module.new(test: number): schema
	assert(type(test) == "number")
	
	local self: schema_raw = {
		_test = test,
	}
	return setmetatable(self, {__index=module})
end

function module.GetTest(self: schema): number
	return self._test
end

function module.ComputeSomething(self: schema): number
	return self:GetTest() * 3
end

return module

I believe in this use case it shouldn’t require much additional technology and could be handled directly. Maybe I’m wrong? Intellisense works great doing this, we use this technique all through our projects.