Script Editor API: Now in Beta!

I’ve been waiting for this for a while now, I’ll definitely try it out soon!

1 Like

That’s something you can already do on your own, just format the table contents into the Lua syntax and call EditTextAsync.

local function formatTable(tbl)
	local out = {"{"}
	
	for key, value in tbl do
		-- You'll want to handle datatypes instead of just using tostring but this is a simple demo
		table.insert(out, string.format("\t%s = %q", tostring(key), tostring(value)))
	end
	
	table.insert(out, "}")
	return table.concat(out, "\n")
end

print(formatTable({
	test = "hello"
}))

--[[ Output:
{
	test = "hello"
}
--]]

2 Likes

Currently I serialize tables generated by a plugin to a string using a bit of a imperfect method before writing to the Source property. Sometimes key value pairs don’t correctly serialize leaving it full of syntax errors at times. This would be close to something such as the JSONEncode method.

That’s not in scope of this script editor API, it has nothing to do with the editor. Post in #feature-requests:engine-features instead so it reaches the right engineers!

1 Like

This could really be useful to help beginners and advanced developpers with common mistakes that the default IDE doesn’t detect.

2 Likes

It would be useful if it was possibe to replace text with EditTextAsync instead of having it just insert text.

Also it will probably remain internal but RegisterLSPCallback :eyes:

2 Likes

I don’t have post access in that section.

2 Likes

You can replace text with EditTextAsync? It should replace the span between startLine, startCharacter and endLine, endCharacter.

See ScriptDocument | Roblox Creator Documentation

1 Like

Turns out it was me misunderstanding how it works, was parsing the same value into start and end when end should probably be +1

Thanks for the tip :+1:

and now, what i wanted to initially do (after getting around 20,000 utf8 splicing errors)
progress bar

22 Likes

will there be a way in the future to detect key presses whilst inside a script?

1 Like

That’s was good, i think to my focus on Script Editor for making plugins now beta API for future, inspired for related for years added to come for update to safety my focus on Script!

1 Like

Now this API exists, here is recommended permission.

  • Read: Almost everyone. With this, we can check script before activating.
  • Edit: Since some explorer knows how to code, Dev only is best.
2 Likes

This is perfect for my plugin. thank you for this!

1 Like

This od fantastic! We can see when somebody edit US scripts!

Good job! There is one thing that I would like to be added to the api though, and the thing I think should be added is the ability to add things to the Autocomplete window. For example I could add “GS” as an Autocomplete option and when GS is selected it types “game:GetService()” for me.

This would make the Script Editor way more customizable from a plugin perspective and help alot with development. Thank you

3 Likes

This was already possible via a scripts Source property. Contains the entire code in a string.

1 Like

It seems like LuaSoureContainers parented to nothing don’t receive ScriptDocuments? Using this in the command bar prints nil. _G.scrippet.plugin is a Plugin instance. The print is called while the script is still open.

local s = Instance.new("ModuleScript"); _G.scrippet.plugin:OpenScript(s); task.wait(1); print(game:GetService("ScriptEditorService"):FindScriptDocument(s))

Being able to open a temporary script parented to nothing is something I want to use to allow users to edit a snippet in the Roblox Studio script editor.

4 Likes

I dont know if i did it wrong but .TextDocumentDidChange returns a document parameter that doesn’t have a script object (:GetScript() returns nil)

I just realized my problem is exactly what the user above is experiencing

I noticed a weird little syntax quirk when I was checking out the API via auto-complete, not quite sure if this was intended:

Also as mentioned above, having any sort of event for enter/backspace detection would greatly be appreciated.

Edit: I also saw some inconsistencies with the type of the changesArray in .TextDocumentDidChange the docs in Roblox Studio say it’s of type any. The new docs on the website in the summary say it’s of type Variant, but then the name describes it as a type array {any}?

1 Like

Yes, I think that UserInputService should be allowed to detect keystrokes made inside of the Script Editor.

2 Likes