# ScriptEditorService

Roblox Engine API class from Roblox Studio 0.744.0.7441077 (version-7aaa6838d36c4448).

- Inherits from, nearest first: [Instance](https://rapi.sleaze.dev/classes/Instance.md), [Object](https://rapi.sleaze.dev/classes/Object.md)
- Tags: Not creatable, Not replicated, Service
- Memory category: Instances
- HTML page: https://rapi.sleaze.dev/classes/ScriptEditorService/
- Roblox documentation: https://create.roblox.com/docs/reference/engine/classes/ScriptEditorService

This service is used for interacting with [`ScriptDocument`](https://rapi.sleaze.dev/classes/ScriptDocument.md) instances.

## Methods

### ClearUriScript

```luau
ScriptEditorService:ClearUriScript(uri: string)
```

- Tags: Roblox script security

### DeregisterAutocompleteCallback

```luau
ScriptEditorService:DeregisterAutocompleteCallback(name: string)
```

- Tags: Plugin security

Removes a previously registered callback with the name `name`.

Parameters:

- `name`: The identifier that was used when registering the callback with [`ScriptEditorService:RegisterAutocompleteCallback()`](https://rapi.sleaze.dev/classes/ScriptEditorService.md).

### DeregisterScriptAnalysisCallback

```luau
ScriptEditorService:DeregisterScriptAnalysisCallback(name: string)
```

- Tags: Plugin security

Removes a previously registered callback with the name `name`.

Parameters:

- `name`: The identifier that was used when registering the callback with [`ScriptEditorService:RegisterScriptAnalysisCallback()`](https://rapi.sleaze.dev/classes/ScriptEditorService.md).

### EditSourceAsyncWithRanges

```luau
ScriptEditorService:EditSourceAsyncWithRanges(script: LuaSourceContainer, newText: string, startLine: number, startCharacter: number, endLine: number, endCharacter: number): ...any
```

- Tags: Yields, Roblox script security

### FindScriptDocument

```luau
ScriptEditorService:FindScriptDocument(script: LuaSourceContainer): ScriptDocument
```

- Tags: Plugin security

Returns the open [`ScriptDocument`](https://rapi.sleaze.dev/classes/ScriptDocument.md) corresponding to the given [`LuaSourceContainer`](https://rapi.sleaze.dev/classes/LuaSourceContainer.md), or `nil` if the given script is not open.

Parameters:

- `script`: The [`LuaSourceContainer`](https://rapi.sleaze.dev/classes/LuaSourceContainer.md) (such as a [`Script`](https://rapi.sleaze.dev/classes/Script.md), [`LocalScript`](https://rapi.sleaze.dev/classes/LocalScript.md), or [`ModuleScript`](https://rapi.sleaze.dev/classes/ModuleScript.md)) to find the open document for.

Returns: The open [`ScriptDocument`](https://rapi.sleaze.dev/classes/ScriptDocument.md) corresponding to the given script, or nil if the script is not currently open in the Script Editor.

### ForceReloadSource

```luau
ScriptEditorService:ForceReloadSource(uri: string, newsrc: string)
```

- Tags: Roblox script security

### GetEditorSource

```luau
ScriptEditorService:GetEditorSource(script: LuaSourceContainer): string
```

- Tags: Plugin security

Returns the edit-time source for the given script.

Parameters:

- `script`: The [`LuaSourceContainer`](https://rapi.sleaze.dev/classes/LuaSourceContainer.md) to retrieve the edit-time source text for.

Returns: The edit-time source text of the script as a string.

### GetScriptDocuments

```luau
ScriptEditorService:GetScriptDocuments(): { Instance }
```

- Tags: Plugin security

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

Returns: An array of [`ScriptDocument`](https://rapi.sleaze.dev/classes/ScriptDocument.md) objects representing all currently open editor tabs, including the command bar.

### IsAutocompleteCallbackRegistered

```luau
ScriptEditorService:IsAutocompleteCallbackRegistered(name: string): boolean
```

- Tags: Roblox script security

### IsScriptAnalysisCallbackRegistered

```luau
ScriptEditorService:IsScriptAnalysisCallbackRegistered(name: string): boolean
```

- Tags: Roblox script security

### OpenScriptDocumentAsync

```luau
ScriptEditorService:OpenScriptDocumentAsync(script: LuaSourceContainer, options: { [string]: any }? = nil): ...any
```

- Tags: 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.

Parameters:

- `script`: The [`LuaSourceContainer`](https://rapi.sleaze.dev/classes/LuaSourceContainer.md) to open in the Script Editor.
- `options`: A dictionary that supports the following options:

- `Temporary` — Boolean. Whether to open the script in a preview tab. Default is false.
- `HighlightRange` — A nested dictionary containing a line and character range to highlight in the editor. Example: `HighlightRange = { Start = { Line = 10, Character = 1 }, End = { Line = 15, Character = 20 }}`.

Returns: A tuple where the first value is a boolean indicating success and the second is nil on success or a string describing the problem on failure.

### OpenStringValueDocumentAsync

```luau
ScriptEditorService:OpenStringValueDocumentAsync(stringValue: StringValue, options: { [string]: any }? = nil): ...any
```

- Tags: Yields, Roblox script security

### OpenTemporaryDocumentAsync

```luau
ScriptEditorService:OpenTemporaryDocumentAsync(scriptId: string, initialContent: string): ...any
```

- Tags: Yields, Roblox script security

### RegisterAutocompleteCallback

```luau
ScriptEditorService:RegisterAutocompleteCallback(name: string, priority: number, callbackFunction: (...any) -> ...any)
```

- Tags: Plugin security

Registers an autocomplete callback `callbackFunction` named `name` with priority `priority`.

Parameters:

- `name`: A unique identifier for this callback, used to deregister it later with [`ScriptEditorService:DeregisterAutocompleteCallback()`](https://rapi.sleaze.dev/classes/ScriptEditorService.md).
- `priority`: The invocation order among registered callbacks; lower values run first.
- `callbackFunction`: The function invoked during autocomplete with the signature `(Request: table, Response: table) -> table`.

### RegisterScriptAnalysisCallback

```luau
ScriptEditorService:RegisterScriptAnalysisCallback(name: string, priority: number, callbackFunction: (...any) -> ...any)
```

- Tags: Plugin security

Registers a Script Analysis callback `callbackFunction` named `name` with `priority`.

Parameters:

- `name`: A unique identifier for this callback, used to deregister it later with [`ScriptEditorService:DeregisterScriptAnalysisCallback()`](https://rapi.sleaze.dev/classes/ScriptEditorService.md).
- `priority`: The invocation order among registered callbacks; lower values run first.
- `callbackFunction`: The function invoked during Script Analysis with the signature `(Request: table) -> table`, returning a response containing diagnostics.

### SetUriScript

```luau
ScriptEditorService:SetUriScript(uri: string, source: string)
```

- Tags: Roblox script security

### StripComments

```luau
ScriptEditorService:StripComments(code: string): string
```

- Tags: Roblox script security

### UpdateSourceAsync

```luau
ScriptEditorService:UpdateSourceAsync(script: LuaSourceContainer, callback: (...any) -> ...any)
```

- Tags: Yields, Plugin security

Generates new content from the old script and updates the script editor if it's open, or the [`Script`](https://rapi.sleaze.dev/classes/Script.md) instance if the script editor is closed.

Parameters:

- `script`: Script instance to be updated.
- `callback`: The function to return new script content.

## Events

### TextDocumentDidChange

```luau
ScriptEditorService.TextDocumentDidChange: RBXScriptSignal<(document: ScriptDocument, changesArray: any)>
```

- Tags: Plugin security

Fires just after a [`ScriptDocument`](https://rapi.sleaze.dev/classes/ScriptDocument.md) changes.

### TextDocumentDidClose

```luau
ScriptEditorService.TextDocumentDidClose: RBXScriptSignal<(oldDocument: ScriptDocument)>
```

- Tags: Plugin security

Fires just before a [`ScriptDocument`](https://rapi.sleaze.dev/classes/ScriptDocument.md) object is destroyed, which happens right after the script editor closes.

### TextDocumentDidOpen

```luau
ScriptEditorService.TextDocumentDidOpen: RBXScriptSignal<(newDocument: ScriptDocument)>
```

- Tags: Plugin security

Fires just after a [`ScriptDocument`](https://rapi.sleaze.dev/classes/ScriptDocument.md) object is created and parented to the service, which happens right after the script editor opens.

## Inherited members

- From [Instance](https://rapi.sleaze.dev/classes/Instance.md): `Archivable`, `archivable`, `Attributes`, `AttributesReplicate`, `AttributesSerialize`, `HistoryId`, `Name`, `Parent`, `PredictionMode`, `PropertyStatusStudio`, `RobloxLocked`, `SerializedOverrides`, `SourceAssetId`, `Tags`, `UniqueId`, `numExpectedDirectChildren`, `DataCost`, `Capabilities`, `DefinesCapabilities`, `IsInSandbox`, `Sandboxed`, `AddTag`, `ClearAllChildren`, `Clone`, `Destroy`, `FindFirstAncestor`, `FindFirstAncestorOfClass`, `FindFirstAncestorWhichIsA`, `FindFirstChild`, `FindFirstChildOfClass`, `FindFirstChildWhichIsA`, `FindFirstDescendant`, `GetActor`, `GetAttribute`, `GetAttributeChangedSignal`, `GetAttributes`, `GetChildren`, `GetDebugId`, `GetDescendants`, `GetFullName`, `GetStyled`, `GetStyledPropertyChangedSignal`, `GetTags`, `HasTag`, `IsAncestorOf`, `IsDescendantOf`, `IsPropertyModified`, `QueryDescendants`, `RemoveTag`, `ResetPropertyToDefault`, `SetAttribute`, `WaitForChild`, `Remove`, `children`, `clone`, `destroy`, `findFirstChild`, `getChildren`, `isDescendantOf`, `remove`, `AncestryChanged`, `AttributeChanged`, `ChildAdded`, `ChildRemoved`, `DescendantAdded`, `DescendantRemoving`, `Destroying`, `StyledPropertiesChanged`, `childAdded`
- From [Object](https://rapi.sleaze.dev/classes/Object.md): `ClassName`, `className`, `GetPropertyChangedSignal`, `IsA`, `isA`, `Changed`
