Script Editor API: Now in Beta!

Couldn’t you accomplish pretty much the same thing with loadstring?

1 Like

Yes! I needed this so much for my plugin. Now everything I need is an ability to highligh certain string patterns in the editor and open temporary script tabs.

Edit: Is this only for scripts which are opened in the script editor? :frowning:

1 Like

They could already do that.

5 Likes

Yes, ScriptDocument represents a Studio Script Editor, so a Script that is not open in an editor will not have a ScriptDocument.

Suggestions welcome if this stops you from doing something!

3 Likes

Finally we can make plugins that can extend script editor functionality, can’t wait to see what talented creators will make. It’s gonna be a big upgrade for me since I use script editor 99% of my time spent in studio.

Also, is hot reloading a thing?

4 Likes

An epic idea, what if we could freely place and remove endpoints?? Better yet, an epic API feature for this class, the ability to pause and resume scripts!

2 Likes

Finally!

Will there be API to add things to the autocomplete menu? Or for things like displaying GUIs?

Imagine if you could have a ViewportFrame displayed when you hover over a variable holding a part, and that you could have the basic tools like resizing. Or if you could add custom functions shown in autocomplete, and when you press tab, it actually defines the function at the top of the script or at a place marked with a comment. Or if you could make it so changes other team members make would be shown above as a notification.

5 Likes

Dude that’s another solid feature suggestion. Imagine having a custom module that acts like a class, and being able to autocomplete using your own API… MIND BLOWN

4 Likes

THANK YOU! I’m working on a node-based visual scripter plugin and this will be just perfect to ease my development of it, thank you!

Every single person who contributed to this has earned my eternal respect.

3 Likes

Any chance we could get an API to close an open ScriptDocument?

You can already open scripts with plugin:OpenScript()

Could you walk me through your use-case for closing an editor from a plugin?

Not OP, but this could allow for adding functionality similar to VSCode’s Ctrl + K W shortcut, which closes all open script documents. It’d also allow for similar functionality such as mapping a keybind to close all scripts to the right of the open file.

2 Likes

Rojo has a feature called “Open Scripts Externally” that will attempt to open a file in an external editor when you open the corresponding script in Studio. Since the file opens in your external editor Rojo closes the one in Studio. Here’s the relevant code:

https://github.com/rojo-rbx/rojo/blob/master/plugin/src/ServeSession.lua#L180

-- Force-close the script inside Studio... with a small delay in the middle
-- to prevent Studio from crashing.
spawn(function()
	local existingParent = activeScript.Parent
	activeScript.Parent = nil

	for i = 1, 3 do
		RunService.Heartbeat:Wait()
	end

	activeScript.Parent = existingParent
end)

As you can see this is pretty hacky and it interferes with other Rojo features because you are removing the script from the DataModel temporarily.

EDIT: I’m not sure if the delay is necessary. I just tested it and it doesn’t crash. However, it would still be nice to close a script without removing it.

8 Likes

Ok! I can’t promise anything on any particular API requests, but it seems reasonable to me.

As a side note: That delay should be unnecessary. Studio should not crash regardless of what you do to a script you have open. If you can find a case where it does, please report it as a bug.

1 Like

Wow, this opens up a whole lot of opportunities for making Roblox’s editor come close to the capabilities of Visual Studio Code when it comes to scripting!

Will there be support for serializing tables into scripts in the future? This would be incredibly useful for some modules I use since I use a lot of data based configuration.

Can we have an API to set the cursor position? Being able to read it is a huge step forward, but being able to set it is the second half of every “cursor control” feature request use case. For example, VSCode snippets allow you to indicate where the cursor should be placed when the snippet is used, so you can make the snippet put the cursor in the middle of a function call or table definition. We currently have no way to accomplish this.

12 Likes

When you reopen a Studio place, it automatically opens the scripts you had open last session, but that doesn’t fire the document opened event. I assume this is because they reopen before the plugins are loaded. Can we have an API to :GetOpenDocuments() so we can just loop over them and handle anything that was already open before the plugin loaded? Even if they’re just children of the service, Players has :GetPlayers() because it’s safer and more idiomatic.

12 Likes

I’m not entirely sure what you’re asking for here, could you be more specific?

1 Like