Introducing ReFactor, a plugin that provides refactor renaming support for Roblox Studio!
When renaming a ModuleScript, every reference to that ModuleScript or its class will automatically be renamed to the new ModuleScript name!
Demo:
Note: This plugin only works for renaming a ModuleScript
To learn more about what refactoring does: Refactor rename - Visual Studio (Windows) | Microsoft Learn
If you don’t want a script to get refactored, type --/nofactor at the top of the script
This would be very complex to add because the plugin would have to interpret the code to understand when a variable is truly a reference or not, and there would be a lot more room to cause false positives when refactoring the codebase. ModuleScripts are a lot easier to deal with because you have to use require to access them, so it’s easy for the plugin to tell if a script is referencing a ModuleScript or not. (This means a singleton architecture probably won’t work with this plugin and that’s by design to avoid false positives)
This plugin is not really a one-size-fits-all solution, as it’s designed for a specific code style (which you could probably guess in the video). If you use any extensions like BTRoblox, then you should be able to download the source code for the plugin, which you are free to modify the plugin to fit your personal needs.
Would be nice if this also refactored modulescript paths, for example lets say i have this in multiple scripts:
local MyModule = require(workspace.MyModule)
And i decided to reorganize my stuff since workspace is a bad place to store modules, so i moved it to ReplicatedStorage.
Would be nice if this worked for that and changed it to:
local MyModule = require(game:GetService(“ReplicatedStorage”).MyModule)
Sounds interesting. I will see what I can do, but I won’t promise anything. If I were to implement this feature, I would probably make ReplicateStorage its own variable though.
example:
-- before
local MyModule = require(workspace.MyModule)
--after
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local MyModule = require(ReplicatedStorage.MyModule)
Scripts will not be updated if the renamed ModuleScript does not or did not have a unique ModuleScript name. This way, if you have multiple ModuleScripts containing the same name, ReFactor will not make script updates until the old and new names of a ModuleScript are unique. This is to avoid potential update conflicts caused by ambiguity.
There is now a toolbar button that, when enabled, turns on the plugin. This way, if ReFactor ever works against your intention when renaming ModuleScripts, you can simply toggle off this button to temporarily disable ReFactor until the conflict is resolved.
ReFactor now outputs a list of all the scripts it updated whenever the plugin is triggered. This ensures that the developer is actively aware of the plugin when it is triggered, in case the plugin ever leads to a conflict of interest.
This plugin uses HTTP requests to get an up-to-date list of all class names in the Roblox API. If you want to learn more, here is the solution I used for this.
Also ReFactor had some bugs that should be fixed now! Keep in mind that the plugin sometimes refuses to refactor a module name if it could lead to ambiguity.
No, unfortunately. ReFactor works by simply using a regex to find all instances of the module name in all scripts. It does not use a parser to find references of a script, so reparenting the module without renaming it will not be caught by ReFactor.
Renaming a module from an ambiguous name to a unique name now refactors the module only (previously, it did not refactor at all).
This means that if you duplicate a Rectangle module and rename the duplicate to Square, only the new module will be refactored to Square. All other scripts referencing the Rectangle module will remain unchanged.
However, if you tried to rename the new Square module back to Rectangle, the module would not refactor, since that could reintroduce ambiguity for the module (for example, if the Square module were modified to require the Rectangle module).