ScriptEditorService
This service is used for interacting with ScriptDocument instances.
Memory category | Instances |
---|
Member index 17
Removed member index 1
History | Member | |
---|---|---|
545 | RegisterLSPCallback(methodToOverride: LSPMethodType, callbackFunction: Function): void |
Description
This service is used for interacting with ScriptDocument instances.
History 32
- 648 Change ReturnType of GetScriptDocuments from Objects to Instances
- 622 Add IsScriptAnalysisCallbackRegistered
- 622 Add IsAutocompleteCallbackRegistered
- 619 Add StripComments
- 597 Change ReturnType of UpdateSourceAsync from Tuple to null
- 592 Add UpdateSourceAsync
- 592 Add EditSourceAsyncWithRanges
- 575 Add GetEditorSource
- 573 Change ReturnType of RegisterScriptAnalysisCallback from void to null
- 573 Change ReturnType of RegisterAutocompleteCallback from void to null
- 573 Change ReturnType of ForceReloadSource from void to null
- 573 Change ReturnType of DeregisterScriptAnalysisCallback from void to null
- 573 Change ReturnType of DeregisterAutocompleteCallback from void to null
- 569 Add ForceReloadSource
- 567 Add RegisterScriptAnalysisCallback
- 567 Add DeregisterScriptAnalysisCallback
- 546 Change Parameters of RegisterAutocompleteCallback from (callbackFunction: Function) to (name: string, priority: int, callbackFunction: Function)
- 546 Add DeregisterAutocompleteCallback
- 545 Remove RegisterLSPCallback
- 545 Add RegisterAutocompleteCallback
- 542 Add OpenScriptDocumentAsync
- 539 Add GetScriptDocuments
- 532 Change Security of TextDocumentDidOpen from RobloxScriptSecurity to PluginSecurity
- 532 Change Security of TextDocumentDidClose from RobloxScriptSecurity to PluginSecurity
- 532 Change Security of TextDocumentDidChange from RobloxScriptSecurity to PluginSecurity
- 532 Change Security of FindScriptDocument from RobloxScriptSecurity to PluginSecurity
- 529 Add FindScriptDocument
- 528 Add TextDocumentDidOpen
- 528 Add TextDocumentDidClose
- 528 Add TextDocumentDidChange
- 528 Add RegisterLSPCallback
- 528 Add ScriptEditorService
Members 17
DeregisterAutocompleteCallback
Parameters (1) | ||
---|---|---|
name | string | |
Returns (1) | ||
null |
Removes a previously registered callback with the name name
.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 573 Change ReturnType of DeregisterAutocompleteCallback from void to null
- 546 Add DeregisterAutocompleteCallback
DeregisterScriptAnalysisCallback
Parameters (1) | ||
---|---|---|
name | string | |
Returns (1) | ||
null |
Removes a previously registered callback with the name name
.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 573 Change ReturnType of DeregisterScriptAnalysisCallback from void to null
- 567 Add DeregisterScriptAnalysisCallback
EditSourceAsyncWithRanges
Parameters (6) | ||
---|---|---|
script | LuaSourceContainer | |
newText | string | |
startLine | int | |
startCharacter | int | |
endLine | int | |
endCharacter | int | |
Returns (1) | ||
Tuple |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 1
FindScriptDocument
Parameters (1) | ||
---|---|---|
script | LuaSourceContainer | |
Returns (1) | ||
ScriptDocument |
Returns the open ScriptDocument corresponding to the given LuaSourceContainer, or nil if the given script is not open.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 532 Change Security of FindScriptDocument from RobloxScriptSecurity to PluginSecurity
- 529 Add FindScriptDocument
ForceReloadSource
Parameters (2) | ||
---|---|---|
uri | string | |
newsrc | string | |
Returns (1) | ||
null |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 573 Change ReturnType of ForceReloadSource from void to null
- 569 Add ForceReloadSource
GetEditorSource
Parameters (1) | ||
---|---|---|
script | LuaSourceContainer | |
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.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
History 1
- 575 Add GetEditorSource
GetScriptDocuments
Parameters (0) | ||
---|---|---|
No parameters. | ||
Returns (1) | ||
Instances |
Returns an array of the currently open script documents, including the command bar.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 648 Change ReturnType of GetScriptDocuments from Objects to Instances
- 539 Add GetScriptDocuments
IsAutocompleteCallbackRegistered
Parameters (1) | ||
---|---|---|
name | string | |
Returns (1) | ||
bool |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 1
IsScriptAnalysisCallbackRegistered
Parameters (1) | ||
---|---|---|
name | string | |
Returns (1) | ||
bool |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 1
OpenScriptDocumentAsync
Parameters (1) | ||
---|---|---|
script | LuaSourceContainer | |
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.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
History 1
RegisterAutocompleteCallback
Parameters (3) | ||
---|---|---|
name | string | |
priority | int | |
callbackFunction | Function | |
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 |
|
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, butdocumentation.value
may be empty.Response.items[n].documentation
specifies the main body of the documentation in itsvalue
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 ahttps
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.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
History 3
- 573 Change ReturnType of RegisterAutocompleteCallback from void to null
- 546 Change Parameters of RegisterAutocompleteCallback from (callbackFunction: Function) to (name: string, priority: int, callbackFunction: Function)
- 545 Add RegisterAutocompleteCallback
RegisterScriptAnalysisCallback
Parameters (3) | ||
---|---|---|
name | string | |
priority | int | |
callbackFunction | Function | |
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 anhttps
request tocreate.roblox.com
; no other URLs display in the editor.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 573 Change ReturnType of RegisterScriptAnalysisCallback from void to null
- 567 Add RegisterScriptAnalysisCallback
StripComments
Parameters (1) | ||
---|---|---|
code | string | |
Returns (1) | ||
string |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 1
- 619 Add StripComments
TextDocumentDidChange
Parameters (2) | |
---|---|
document | ScriptDocument |
changesArray | Variant |
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 }
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 532 Change Security of TextDocumentDidChange from RobloxScriptSecurity to PluginSecurity
- 528 Add TextDocumentDidChange
TextDocumentDidClose
Parameters (1) | |
---|---|
oldDocument | ScriptDocument |
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.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 532 Change Security of TextDocumentDidClose from RobloxScriptSecurity to PluginSecurity
- 528 Add TextDocumentDidClose
TextDocumentDidOpen
Parameters (1) | |
---|---|
newDocument | ScriptDocument |
Fires just after a ScriptDocument object is created and parented to the service, which happens right after the script editor opens.
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 532 Change Security of TextDocumentDidOpen from RobloxScriptSecurity to PluginSecurity
- 528 Add TextDocumentDidOpen
UpdateSourceAsync
Parameters (2) | ||
---|---|---|
script | LuaSourceContainer | |
callback | Function | |
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 |
|
Security | PluginSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 597 Change ReturnType of UpdateSourceAsync from Tuple to null
- 592 Add UpdateSourceAsync
Removed members 1
RegisterLSPCallback
Parameters (2) | ||
---|---|---|
methodToOverride | LSPMethodType | |
callbackFunction | Function | |
Returns (1) | ||
void |
Security | RobloxScriptSecurity |
---|---|
Thread safety | Unsafe |
History 2
- 545 Remove RegisterLSPCallback
- 528 Add RegisterLSPCallback