-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHelperFunctions.lua
57 lines (45 loc) · 1.67 KB
/
HelperFunctions.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
-- HelperFunctions.lua
local AutocompleteHelper = {}
function AutocompleteHelper.isModuleScript(instance: Instance): boolean
return instance.ClassName == "ModuleScript" and not instance:IsDescendantOf(game.CoreGui)
end
function AutocompleteHelper.isService(instance: Instance): boolean
local service
local success, err = pcall(function()
service = game:FindService(instance.ClassName)
end)
if success then
return true
else
return false
end
end
function AutocompleteHelper.getServiceForModule(module: Instance): string?
for _, service in pairs(game:GetChildren()) do
if module:IsDescendantOf(service) then
return tostring(service)
end
end
return nil
end
function AutocompleteHelper.getModuleFullNamePath(module: Instance): string
return module:GetFullName()
end
function AutocompleteHelper.shouldProcessName(name: string): boolean
return name:match("[%w]+") == name and name:match("%d") == nil
end
function AutocompleteHelper.getModuleInitializationString(moduleService: string, moduleName: string, path: string, document: ScriptDocument): string
local serviceAbstraction = string.format('local %s = game:GetService("%s")', moduleService, moduleService)
local moduleAbstraction = string.format('local %s = require(%s)', moduleName, path)
for i = 1, document:GetLineCount() do
local lineString = document:GetLine(i)
if lineString:match("local " .. moduleService) then
return moduleAbstraction
end
end
return serviceAbstraction .. "\n" .. moduleAbstraction
end
function AutocompleteHelper.getServiceInitializationString(serviceName: string): string
return string.format('local %s = game:GetService("%s")', serviceName, serviceName)
end
return AutocompleteHelper