How would I be able to autofill the content of a module script using require that has returned or passed in a function

I want to be able to see the content of a module script when requiring it a.k.a autofill feature. But I want to do it through a function, a specific function that I somehow figure out that I can use in my framework because when using the function it actually returns the Instance so you know everything of its properties and childrens.

The issue with this function is when using it, It only return the Instance and when I try to require it if the Instance is a module script then all of it content would then be gone or autofill not showing

To be honest, I have only tried replacing the code in the function and adding elseif to create a different result but turn out not so I keep it the same when I first created it.

The code containing the function

--!nocheck
type Autofill = typeof(workspace.FindFirstChild)

local Get: Autofill = function(Instance: Instance, Name: string)
	return Instance[Name]
end :: any

local Baseplate = Get(workspace, "Baseplate")

local Module = require(Get(workspace,"ModuleScript"))

Baseplate. --The content of Baseplate is shows
Module. -- The content of Module is not visible nor does autofill

If there no way to make it work with this function is there a least somehow a way to make it work but still through a function that has a parameter called Name that will pass the required module script but still show the autofill?

I feel weird since both the function Get and FindFirstChild work the same… well kinds of but it return the same value. And I know that and if it were to return the same value it should work the same with require on FindFirstChild, like

require(workspace:FindFirstChild("ModuleScript")) -- Does autofill for Module Script

But when doing

require(Get(workspace, "ModuleScript")) -- Doesn't autofill and typed as any

The problem might be related to unknown require: unsupported path but doesn’t both function return the same value? Even when I try to change the return in function Get into require(Instance[Name]) then it would be Instance[Name] it ignore the code in the function Get and doesn’t care what it return so it must return like the type Autofill

Turn out when using the workspace.FindFirstChild with the period operator it doesn’t work with autofill when requiring but when doing it with a colon it work. I thought I might be on something so I decided to create a metatable with workspace as __index so that I can use the colon. So here how the code turn out

type Autofill = typeof(workspace.FindFirstChild)

type Table = { Get: Autofill }

local Table: Table = {}

function Table:Get(name)
	return self[name]
end

type Metatable = typeof(setmetatable(Table, { __index = workspace })) & typeof(workspace) & typeof(Table)

local Metatable: Metatable = setmetatable(Table, { __index = workspace })

require(Metatable.Get(workspace, "ModuleScript")) -- Doesn't autofill the content inside but autofill the outside

require(Metatable:Get("ModuleScript")) -- Doesn't autofill the content inside and doesn't quite recognize the type outside

require(Metatable.FindFirstChild(workspace, "ModuleScript")) -- Doesn't autofill both the outside and inside

require(Metatable:FindFirstChild("ModuleScript")) -- Error : `Expected ':' not '.' calling member function FindFirstChild`

When attempting to use the Get function as a period it work like it should but when using the colon it doesn’t recognize the thing to return anymore it still attempted to typecheck but loses all of it childrens, properties. When using the literal FindFirstChild function itself with the period it failed to autofill, when using the colon it return an error saying Expected ':' not '.' calling member function FindFirstChild but I was using the colon?

Conclusion:
The autofill still maybe not working because of unknown require: unsupported path but doing the colon with FindFirstChild work so I am trying to replicate it but still to no avail.

Attempting to know under the hood I decided to print out the “properties” of workspace using Httpservice encode but to no avail

type Autofill = typeof(workspace.FindFirstChild)

type Table = { Get: Autofill }

local Table: Table = {}

function Table:Get(name)
	return self[name]
end

type Metatable = typeof(setmetatable(Table, { __index = workspace })) & typeof(workspace) & typeof(Table)

local Metatable: Metatable = setmetatable(Table, { __index = workspace })

local HttpService = game:GetService("HttpService")

print(HttpService:JSONEncode(Metatable)) -- {"Get":null}
print(HttpService:JSONEncode(workspace)) -- null

print(HttpService:JSONEncode(Metatable:Get("ModuleScript"))) -- null
print(HttpService:JSONEncode(workspace:FindFirstChild("ModuleScript"))) -- null

print(HttpService:JSONEncode(require(workspace:FindFirstChild("ModuleScript")))) -- {"foo":null}
print(HttpService:JSONEncode(require(Metatable:Get("ModuleScript")))) -- {"foo":null}

print(HttpService:JSONEncode(require(workspace.FindFirstChild(workspace, "ModuleScript")))) -- {"foo":null}
print(HttpService:JSONEncode(require(Metatable.Get(workspace, "ModuleScript")))) -- {"foo":null}

print(HttpService:JSONEncode(workspace.FindFirstChild)) -- null
print(HttpService:JSONEncode(workspace.ModuleScript)) -- null

I will come back with more testing

1 Like

You could probably try using this and modifying it with typechecking:

1 Like

To be honest, I think I’m not gonna be able to achieve what I wanted. I had tried Omega solution and had been testing, I kind of would say it kinda work but not fully when using type Autofill = typeof(workspace.FindFirstChild) it will only autofill the instance if the first parameter well is recognize and valid it doesn’t automatically direct in the table holding the function which kind of frustrating and resulting into not able to recognize the instance define in the second parameter. So maybe this is not possible I can probably find the other solution which certainly work but take long hour to make and that is making a custom plugin to be able to detect and autofill for my framework using the Script Editor API

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.