ScriptEditorService

Show Deprecated
Not Creatable
Service
Not Replicated

This service is used for interacting with ScriptDocument instances.

Summary

Properties

Methods


Removes a previously registered callback with the name name.


Returns the open ScriptDocument corresponding to the given LuaSourceContainer, or nil if the given script is not open.


Returns an array of the currently open script documents, including the command bar.

RegisterAutocompleteCallback(name: string, priority: number, callbackFunction: function): void  

Registers an Autocomplete callback callbackFunction named name with priority priority.

RegisterScriptAnalysisCallback(name: string, priority: number, callbackFunction: function): void  



Requests that a Script Editor open the specified script. Returns (true, nil) if the request succeeds. Returns (false, string) if the request fails, with a string that describes the problem.

Events

TextDocumentDidChange(document: ScriptDocument, changesArray: Variant): RBXScriptSignal  

Fires just after a ScriptDocument changes.


Fires just before a ScriptDocument object is destroyed, which happens right after the script editor closes.


Fires just after a ScriptDocument object is created and parented to the service, which happens right after the script editor opens.

Properties

Methods

DeregisterAutocompleteCallback

void
Plugin Security

Removes a previously registered callback with the name name.

Parameters

name: string

Returns

void

Code Samples

ScriptEditorService:DeregisterAutocompleteCallback

game.ScriptEditorService:DeregisterAutocompleteCallback("foo")

DeregisterScriptAnalysisCallback

void
Plugin Security

Parameters

name: string

Returns

void

FindScriptDocument

Plugin Security

Returns the open ScriptDocument corresponding to the given LuaSourceContainer, or nil if the given script is not open.

Parameters


Returns

Code Samples

ScriptDocument:CloseAsync

local ScriptEditorService = game:GetService("ScriptEditorService")
print(ScriptEditorService:FindScriptDocument(workspace.Script):CloseAsync())
ScriptDocument.ViewportChanged

local ScriptEditorService = game:GetService("ScriptEditorService")
local document = ScriptEditorService:FindScriptDocument(workspace.Script)
document.ViewportChanged:Connect(print)

GetEditorSource

Plugin Security

Parameters


Returns

GetScriptDocuments

Plugin Security

Returns an array of the currently open script documents, including the command bar.


Returns

Code Samples

ScriptEditorService:GetScriptDocuments

local ScriptEditorService = game:GetService("ScriptEditorService")
local scripts = ScriptEditorService:GetScriptDocuments()
for _, doc in pairs(scripts) do
print(doc.Name)
end

RegisterAutocompleteCallback

void
Plugin Security

Registers an Autocomplete callback callbackFunction named name with priority priority.

When the Script Editor invokes Autocomplete, all registered autocomplete callbacks call in order of ascending priority with the autocomplete request and response. Multiple callbacks may share a priority, but then their calling order is unpredictable. Each callback is intended to return a response table with the same format as the response input table. Callbacks shouldn't yield. The first callback invoked receives the internal Autocomplete's response as its response table, and subsequent callbacks receive the previous callback's output as their response table. Callbacks may either modify the passed table or return a new table of the same format.

The callbackFunction must have the following type: (Request: table, Response: table) -> table

The Request table has the following format:


type Request = {
position: {
line: number,
character: number
},
textDocument: {
document: ScriptDocument?,
script: LuaSourceContainer?
}
}
  • position is the one-indexed cursor position where you are autocompleting.
  • textDocument.document is the open ScriptDocument you are completing in, if it exists.
  • textDocument.script is the LuaSourceContainer you are completing in, if it exists.

If both textDocument.document and textDocument.script are present, then they correspond to each other: req.textDocument.document:GetScript() == req.textDocument.script

The Response table has the following format:


type Response = {
items: {
{
label: string, -- The label
kind: Enum.CompletionItemKind?,
tags: {Enum.CompletionItemTag}?,
detail: string?,
documentation: {
value: string,
}?,
overloads: number?,
learnMoreLink: string?,
codeSample: string?,
preselect: boolean?,
textEdit: {
newText: string,
replace: { start: { line: number, character: number }, ["end"]: { line: number, character: number } },
}?
}
}
}
  • Response.items is an array of the completion items. The order of this array is insignificant, and it resorts in the editor as the user types.
  • Response.items[n].label is the label of the item which display in the Autocomplete menu.
  • Response.items[n].kind specifies what type of Autocomplete item this is. Primarily this controls the icon given to the item in the editor. Not all kinds have a unique icon. If not specified, the editor uses the "Text" icon. Unsupported kinds default to displaying the "Property" icon.
  • Response.items[n].tags specifies an array of tags describing this completion item. See the CompletionItemTag for details on their function.
  • Response.items[n].details specifies a string describing details about the completion item. For default items, this is a string representation of their type. Note that, in order for the documentation widget to display, documentation must be present, but documentation.value may be empty.
  • Response.items[n].documentation specifies the main body of the documentation in its value field. documentation is present, even if value is empty, so the documentation window displays if either details or overloads are specified.
  • Response.items[n].overloads specifies the number of overloads of a function autocompletion.
  • Response.items[n].learnMoreLink links to a relevant page on the creator docs. This URL must be an https request to create.roblox.com, no other URLs display in the editor.
  • Response.items[n].codeSample specifies a sample use of the completion item. documentation must be non-empty to display this field.
  • Response.items[n].preselect If true, the editor sorts this completion item ahead of all others and selects it for the user by default. No effect if false or missing.
  • Response.items[n].textEdit If present, accepting the completion applies this text edit - replacing the span between the positions start and end with newText.

If a callback returns a malformed result or encounters an error, the editor discards the modified Response table and uses the built-in Autocomplete result list.

Parameters

name: string
priority: number
callbackFunction: function

Returns

void

Code Samples

ScriptEditorService:RegisterAutocompleteCallback

type Request = {
position: {
line: number,
character: number
},
textDocument: {
document: ScriptDocument?,
script: LuaSourceContainer?
}
}
type Response = {
items: {
{
label: string,
kind: Enum.CompletionItemKind?,
tags: {Enum.CompletionItemTag}?,
detail: string?,
documentation: {
value: string,
}?,
overloads: number?,
learnMoreLink: string?,
codeSample: string?,
preselect: boolean?,
textEdit: {
newText: string,
replace: {
start: { line: number, character: number },
["end"]: { line: number, character: number }
},
}?
}
}
}
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService:RegisterAutocompleteCallback("foo", 1, function(
Req : Request, Resp : Response): Response
table.insert(Resp.items, {label="foo", preselect=true})
return Resp
end)

RegisterScriptAnalysisCallback

void
Plugin Security

Parameters

name: string
priority: number
callbackFunction: function

Returns

void

OpenScriptDocumentAsync

Yields
Plugin Security

Requests that a Script Editor open the specified script. Returns (true, nil) if the request succeeds. Returns (false, string) if the request fails, with a string that describes the problem.

If the script is already open, this function succeeds and switches tabs to the associated editor.

Parameters


Returns

Code Samples

ScriptEditorService:OpenScriptDocumentAsync

local ScriptEditorService = game:GetService("ScriptEditorService")
local script = workspace.Script
print(ScriptEditorService:OpenScriptDocumentAsync(script))

Events

TextDocumentDidChange

Plugin Security

Fires just after a ScriptDocument changes. The textChanged is an array of change structures of the format:

{ range : { start : { line : number, character : number }, end : { line : number, character : number } }, text: string }

Parameters

document: ScriptDocument
changesArray: Variant

Code Samples

ScriptEditorService.TextDocumentDidChange

game:GetService("ScriptEditorService").TextDocumentDidChange:Connect(
function(doc, changes)
print("Changed", doc, changes)
end)

TextDocumentDidClose

Plugin Security

Fires just before a ScriptDocument object is destroyed, which happens right after the script editor closes. After this event fires, the ScriptDocument enters a "Closed" state, and trying to call its methods throws an error. ScriptDocument objects aren't reusable, even if the script editor reopens the same script.

Parameters

oldDocument: ScriptDocument

Code Samples

ScriptEditorService.TextDocumentDidClose

game:GetService("ScriptEditorService").TextDocumentDidClose:Connect(
function(doc)
print("Closed", doc)
end)

TextDocumentDidOpen

Plugin Security

Fires just after a ScriptDocument object is created and parented to the service, which happens right after the script editor opens.

Parameters

newDocument: ScriptDocument

Code Samples

ScriptEditorService.TextDocumentDidOpen

game:GetService("ScriptEditorService").TextDocumentDidOpen:Connect(
function(doc)
print("Opened", doc)
end)