Reference API Roblox

Engine API

Website

Related

Reference API Roblox

ScriptEditorService

This service is used for interacting with ScriptDocument instances.

This class is not replicated. Its interface does not cross the network boundary.
This class is not creatable. Instances of this class cannot be created with Instance.new.
This class is a service. It is a singleton that may be acquired with GetService.
Tags: [NotCreatable, Service, NotReplicated]

Member index 17

HistoryMember
573DeregisterAutocompleteCallback(name: string): null
573DeregisterScriptAnalysisCallback(name: string): null
592EditSourceAsyncWithRanges(script: LuaSourceContainer, newText: string, startLine: int, startCharacter: int, endLine: int, endCharacter: int): Tuple
532FindScriptDocument(script: LuaSourceContainer): ScriptDocument
573ForceReloadSource(uri: string, newsrc: string): null
575GetEditorSource(script: LuaSourceContainer): string
648GetScriptDocuments(): Instances
622IsAutocompleteCallbackRegistered(name: string): bool
622IsScriptAnalysisCallbackRegistered(name: string): bool
542OpenScriptDocumentAsync(script: LuaSourceContainer): Tuple
573RegisterAutocompleteCallback(name: string, priority: int, callbackFunction: Function): null
573RegisterScriptAnalysisCallback(name: string, priority: int, callbackFunction: Function): null
619StripComments(code: string): string
597UpdateSourceAsync(script: LuaSourceContainer, callback: Function): null
532TextDocumentDidChange(document: ScriptDocument, changesArray: Variant)
532TextDocumentDidClose(oldDocument: ScriptDocument)
532TextDocumentDidOpen(newDocument: ScriptDocument)
inherited from Instance
553Archivable: bool
635Capabilities: SecurityCapabilities
553Name: string
553Parent: Instance
635Sandboxed: bool
616UniqueId: UniqueId
576AddTag(tag: string): null
573ClearAllChildren(): null
462Clone(): Instance
573Destroy(): null
486FindFirstAncestor(name: string): Instance
486FindFirstAncestorOfClass(className: string): Instance
486FindFirstAncestorWhichIsA(className: string): Instance
486FindFirstChild(name: string, recursive: bool = false): Instance
486FindFirstChildOfClass(className: string): Instance
486FindFirstChildWhichIsA(className: string, recursive: bool = false): Instance
486FindFirstDescendant(name: string): Instance
563GetActor(): Actor
486GetAttribute(attribute: string): Variant
462GetAttributeChangedSignal(attribute: string): RBXScriptSignal
631GetAttributes(): Dictionary
648GetChildren(): Instances
462GetDebugId(scopeLength: int = 4): string
486GetDescendants(): Array
486GetFullName(): string
641GetStyled(name: string): Variant
576GetTags(): Array
576HasTag(tag: string): bool
486IsAncestorOf(descendant: Instance): bool
486IsDescendantOf(ancestor: Instance): bool
580IsPropertyModified(name: string): bool
573Remove(): null
576RemoveTag(tag: string): null
580ResetPropertyToDefault(name: string): null
573SetAttribute(attribute: string, value: Variant): null
462WaitForChild(childName: string, timeOut: double): Instance
648children(): Instances
553clone(): Instance
573destroy(): null
553findFirstChild(name: string, recursive: bool = false): Instance
648getChildren(): Instances
553isDescendantOf(ancestor: Instance): bool
573remove(): null
462AncestryChanged(child: Instance, parent: Instance)
462AttributeChanged(attribute: string)
462ChildAdded(child: Instance)
462ChildRemoved(child: Instance)
462DescendantAdded(descendant: Instance)
462DescendantRemoving(descendant: Instance)
500Destroying()
553childAdded(child: Instance)
inherited from Object
647ClassName: string
647className: string
647GetPropertyChangedSignal(property: string): RBXScriptSignal
647IsA(className: string): bool
650isA(className: string): bool
647Changed(property: string)

Removed member index 1

HistoryMember
545RegisterLSPCallback(methodToOverride: LSPMethodType, callbackFunction: Function): void

Description

This service is used for interacting with ScriptDocument instances.

History 32

Members 17

DeregisterAutocompleteCallback

Parameters (1)
namestring
Returns (1)
null

Removes a previously registered callback with the name name.

History 2

DeregisterScriptAnalysisCallback

Parameters (1)
namestring
Returns (1)
null

Removes a previously registered callback with the name name.

History 2

EditSourceAsyncWithRanges

Parameters (6)
scriptLuaSourceContainer
newTextstring
startLineint
startCharacterint
endLineint
endCharacterint
Returns (1)
Tuple
This function yields. It will block the calling thread until completion.

History 1

Tags: [Yields]

FindScriptDocument

Parameters (1)
scriptLuaSourceContainer
Returns (1)
ScriptDocument

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

History 2

ForceReloadSource

Parameters (2)
uristring
newsrcstring
Returns (1)
null

History 2

GetEditorSource

Parameters (1)
scriptLuaSourceContainer
Returns (1)
string

Returns the edit-time source for the given script.

If the script is open in the Script Editor, this method returns the text currently being displayed in the editor. If the script is not open in the editor, the method returns the text that the editor would display if it's opened. The edit-time source is not always be consistent with the Script.Source property.

History 1

GetScriptDocuments

Parameters (0)
No parameters.
Returns (1)
Instances

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

History 2

IsAutocompleteCallbackRegistered

Parameters (1)
namestring
Returns (1)
bool

History 1

IsScriptAnalysisCallbackRegistered

Parameters (1)
namestring
Returns (1)
bool

History 1

OpenScriptDocumentAsync

Parameters (1)
scriptLuaSourceContainer
Returns (1)
Tuple

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.

This function yields. It will block the calling thread until completion.

History 1

Tags: [Yields]

RegisterAutocompleteCallback

Parameters (3)
namestring
priorityint
callbackFunctionFunction
Returns (1)
null

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:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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 a 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.

History 3

RegisterScriptAnalysisCallback

Parameters (3)
namestring
priorityint
callbackFunctionFunction
Returns (1)
null

Registers a Script Analysis callback callbackFunction named name with priority. When Script Analysis in Studio runs, all registered callbacks call in order of ascending priority. Each callback is intended to return a response table matching the format specified below. Callbacks should not yield.

The request table has the following format, where script is the LuaSourceContainer that is going to be analyzed.

type Request = {
  script: LuaSourceContainer?
}

The response table has the following format, where diagnostics is an array of diagnostic tables. Each diagnostic table has the entries listed below.

type Response = {
  diagnostics: {
    {
      range: {
        start: {
          line: number,
          character: number,
        },
        ["end"]: {
          line: number,
          character: number,
        }
      },
      code: string?,
      message: string,
      severity: Enum.Severity?,
      codeDescription: { href: string }?
    }
  }
}
  • range represents a text range that should be highlighted by the linter, providing what line/character to start highlighting and what line/character to stop highlighting.
  • code is a label for the message.
  • message is a warning message to be displayed for the line. This will also appear on a tooltip when the user hovers their cursor over the line in the Script Editor.
  • severity is a Severity value for the diagnostics. This determines how the diagnostic is categorized in the Script Analysis tool in Studio, as well as how text is highlighted in the Script Editor.
  • codeDescription 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.

History 2

StripComments

Parameters (1)
codestring
Returns (1)
string

History 1

TextDocumentDidChange

Parameters (2)
documentScriptDocument
changesArrayVariant

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 }

History 2

TextDocumentDidClose

Parameters (1)
oldDocumentScriptDocument

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.

History 2

TextDocumentDidOpen

Parameters (1)
newDocumentScriptDocument

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

History 2

UpdateSourceAsync

Parameters (2)
scriptLuaSourceContainer
callbackFunction
Returns (1)
null

Returns the edit-time Script.Source for the given script.

This function calls the passed callback using the old contents of the script to calculate the new contents of the script.

If the script is open in the Script Editor, then it issues a request to the editor to update its source. The editor may reject this update if the Script.Source property was out of date with the user's version of the script when this function was called, in which case the callback will be re-invoked and the attempt will be repeated.

The callback may not yield. If the callback returns nil, the operation is cancelled. This function yields until the operation is cancelled or succeeds.

If the script is not open in the editor, the new content updates to the script source, which is the text the editor would display if it is opened.

1
2
3
4
local ses = game:GetService('ScriptEditorService')
ses:UpdateSourceAsync(Workspace.Script, function(oldContent)
  return oldContent .. " World!"
end)
This function yields. It will block the calling thread until completion.

History 2

Tags: [Yields]

Removed members 1

RegisterLSPCallback

Parameters (2)
methodToOverrideLSPMethodType
callbackFunctionFunction
Returns (1)
void

History 2

Settings