ScriptEditorService
*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.
이 서비스는 인스턴스 ScriptDocument와 상호작용하는 데 사용됩니다.
요약
메서드
이전에 등록된 콜백 이름 name 을 제거합니다.
이전에 등록된 콜백 이름 name 을 제거합니다.
지정된 ScriptDocument 에 해당하는 열린 LuaSourceContainer 또는 지정된 스크립트가 열려 있지 않은 경우 nil 를 반환합니다.
지정된 스크립트에 대한 편집 시간 소스를 반환합니다.
명령줄을 포함하여 현재 열린 스크립트 문서 배열을 반환합니다. Returns an array of the currently open script documents, including the command bar.
우선 순위가 callbackFunction 인 자동 완성 콜백 name 을 등록합니다.Registers an autocomplete callback named with priority priority .
스크립트 분석 콜백 callbackFunction 명명된 name 을 priority 로 등록합니다.
스크립트 편집기가 지정된 스크립트를 열도록 요청하는 것.요청이 성공하면 (true, nil)을 반환합니다.요청이 실패하면 문제를 설명하는 문자열을 반환합니다(false, string).
오래된 스크립트에서 새로운 콘텐츠를 생성하고 스크립트 편집기가 열려 있는 경우 또는 스크립트 편집기가 닫힌 경우 스크립트 편집기 인스턴스를 업데이트합니다.
이벤트
변경 후 바로 화재가 발생합니다 ScriptDocument 변경.
스크립트 편집기가 닫힐 때 바로 전에 발생하는 화재는 ScriptDocument 개체가 파괴되기 직전입니다.
스크립트 편집기가 열리는 즉시 서비스에 부모로 지정되고 생성된 ScriptDocument 개체에 불이 붙습니다, 이는 스크립트 편집기가 열린 직후에 발생합니다.
속성
메서드
DeregisterAutocompleteCallback
이전에 등록된 콜백 이름 name 을 제거합니다.
매개 변수
반환
코드 샘플
game.ScriptEditorService:DeregisterAutocompleteCallback("foo")
DeregisterScriptAnalysisCallback
이전에 등록된 콜백 이름 name 을 제거합니다.
매개 변수
반환
코드 샘플
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService:DeregisterScriptAnalysisCallback("foo")
FindScriptDocument
지정된 ScriptDocument 에 해당하는 열린 LuaSourceContainer 또는 지정된 스크립트가 열려 있지 않은 경우 nil 를 반환합니다.
매개 변수
반환
코드 샘플
ScriptDocument:CloseAsync
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
local scriptDocument
-- Find the first open script document
for _, document in documents do
-- The Command Bar can't be closed, so don't select it
if not document:IsCommandBar() then
scriptDocument = document
break
end
end
if scriptDocument then
local success, err = scriptDocument:CloseAsync()
if success then
print(`Closed {scriptDocument.Name}`)
else
warn(`Failed to close {scriptDocument.Name} because: {err}`)
end
else
print("No open scripts")
end
Demonstrates using ScriptDocument.ViewportChanged to print the start and end line of the script's viewport when it changes.
To run:
- Ensure Output view is open
- Run the below code in the Command Bar
- Scroll up and down in the opened Script window
--!nocheck
--[[
To run:
1. Ensure Output view is open
2. Run the below code in the Command Bar
3. Scroll up and down in the opened Script window
Print statements from the ViewportChanged event will appear in the Output
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- Create text that spans many lines
local dummyText = string.rep("-- Dummy Text\n", 60)
-- Create a script containing the dummy text and open it
local otherScript = Instance.new("Script")
otherScript.Source = dummyText
otherScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(otherScript)
if not success then
warn(`Failed to open script because: {err}`)
return
end
-- Get a reference to the opened script
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`Script Viewport Changed - startLine: {startLine}, endLine: {endLine}`)
end
-- Connect the ViewportChanged event to the function above that prints the start and end line of the updated viewport
scriptDocument.ViewportChanged:Connect(onViewportChanged)
GetEditorSource
지정된 스크립트에 대한 편집 시간 소스를 반환합니다.
스크립트가 스크립트 편집기에 열려 있으면 이 메서드는 현재 편집기에 표시되는 텍스트를 반환합니다.스크립트가 편집기에서 열리지 않으면 메서드는 편집기가 열릴 경우 표시할 텍스트를 반환합니다.편집 시간 소스는 항상 Script.Source 속성과 일치하지 않습니다.
매개 변수
반환
GetScriptDocuments
명령줄을 포함하여 현재 열린 스크립트 문서 배열을 반환합니다. Returns an array of the currently open script documents, including the command bar.
반환
코드 샘플
Gets all script documents in the place with ScriptEditorService:GetScriptDocuments() and prints their names.
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local scriptDocuments = ScriptEditorService:GetScriptDocuments()
for _, scriptDocument in scriptDocuments do
-- Prints the name of each script
if not scriptDocument:IsCommandBar() then
print(scriptDocument.Name)
end
end
RegisterAutocompleteCallback
우선 순위가 callbackFunction 인 자동 완성 콜백 name 을 등록합니다.Registers an autocomplete callback named with priority priority .
스크립트 편집기가 자동 완성을 호출하면 모든 등록된 자동 완성 콜백이 자동 완성 요청과 응답의 순서대로 호출됩니다.여러 개의 콜백이 우선 순위를 공유할 수 있지만, 그 다음 호출 순서는 예측할 수 없습니다.각 콜백은 응답 입력 테이블과 동일한 형식의 응답 테이블을 반환하도록 의도되었습니다.콜백은 제공되어서는 안됩니다.처음 호출된 첫 번째 콜백은 응답 테이블로 내부 자동 완성 응답을 받고 후속 콜백은 이전 콜백의 출력을 응답 테이블로 받습니다.콜백은 전달된 테이블을 수정하거나 동일한 형식의 새 테이블을 반환할 수 있습니다.
The callbackFunction 는 다음 입력합니다: (Request: table, Response: table) -> table
요청 테이블의 형식은 다음과 같습니다:
type Request = {position: {line: number,character: number},textDocument: {document: ScriptDocument?,script: LuaSourceContainer?}}
- position는 자동으로 완성하는 위치의 한 인덱스 커서 위치입니다.
- textDocument.document 은 완료 중인 열린 ScriptDocument 이며, 존재하는 경우.
- textDocument.script 는 존재하는 경우 완료 중인 LuaSourceContainer 입니다.
둘 다 textDocument.document 와 textDocument.script 가 있으면 서로 일치합니다: req.textDocument.document:GetScript() == req.textDocument.script
응답 테이블의 형식은 다음과 같습니다:
type Response = {items: {{label: string, -- The labelkind: Enum.CompletionItemKind?,tags: {Enum.CompletionItemTag}?,detail: string?,documentation: {value: string,}?,overloads: number?,learnMoreLink: string?,codeSample: string?,preselect: boolean?,textEdit: {newText: string,insert: { start: { line: number, character: number }, ["end"]: { line: number, character: number } },replace: { start: { line: number, character: number }, ["end"]: { line: number, character: number } },}?}}}
- Response.items는 완성 항목의 배열입니다. 이 배열의 순서는 중요하지 않으며, 사용자가 입력하는 순서대로 편집기에 저장됩니다.
- Response.items[n].label는 자동 완성 메뉴에 표시되는 항목의 레이블입니다.
- Response.items[n].kind 이 자동 완성 항목이 어떤 유형인지 지정합니다.주로 이것은 편집기에서 항목에 제공된 아이콘을 제어합니다.모든 종류에 고유한 아이콘이 있는 것은 아닙니다.지정되지 않으면 편집기는 "텍스트" 아이콘을 사용합니다.지원되지 않는 종류는 "속성" 아이콘을 표시하는 기본값으로 설정됩니다.
- Response.items[n].tags 는 이 완성 아이템설명하는 태그 배열을 지정합니다. 기능에 대한 자세한 내용은 Enum.CompletionItemTag 를 참조하십시오.
- Response.items[n].details 완료 아이템대한 세부 정보를 설명하는 문자열을 지정합니다.기본 항목의 경우 이는 해당 입력문자열 표현입니다.문서화 위젯이 표시되려면 documentation 가 있어야 하지만 documentation.value 는 비어있을 수 있습니다.
- Response.items[n].documentation 필드에서 문서의 주요 내용을 지정합니다. specifies the main body of the documentation in its value field.documentation 값이 비어 있더라도 존재하므로 문서화 창에 세부 정보 또는 오버로드가 지정되는지 여부가 표시됩니다.
- Response.items[n].overloads 함수 자동 완성의 오버로드 수를 지정합니다.
- Response.items[n].learnMoreLink 크리에이터 문서의 관련 페이지로 링크합니다.이 URL은 create.roblox.com에 대한 https 요청이어야 하며, 편집기에 다른 URL은 표시되지 않습니다.
- Response.items[n].codeSample 완료 아이템샘플 사용을 지정합니다. documentation 이 필드를 표시하려면 비어 있지 않아야 합니다.
- Response.items[n].preselect 진실이면 편집기가 다른 모든 사람보다 먼저 이 완성 항목을 정렬하고 기본적으로 사용자에게 선택합니다. false 또는 누락된 경우 효과가 없습니다.
- Response.items[n].textEdit 현재 있으면 완료 수락이 이 텍스트 편집을 적용합니다 - 시작 위치와 끝 위치 사이의 스팬을 newText로 삽입하거나 교체합니다.
콜백이 잘못 형식화된 결과를 반환하거나 오류를 발견하면 편집기는 수정된 응답 테이블을 삭제하고 기본 제공 자동 완성 결과 목록을 사용합니다.
매개 변수
반환
코드 샘플
ScriptEditorService:RegisterAutocompleteCallback ScriptEditorService:DeregisterAutocompleteCallback
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
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 autocompleteCallback = function(request: Request, response: Response): Response
local item = {
label = "foo",
preselect = true,
}
table.insert(response.items, item)
return response
end
ScriptEditorService:RegisterAutocompleteCallback("foo", 1, autocompleteCallback)
-- To deregister the callback, run the following code in the Command Bar
ScriptEditorService:DeregisterAutocompleteCallback("foo")
RegisterScriptAnalysisCallback
스크립트 분석 콜백 callbackFunction 명명된 name 을 priority 로 등록합니다.Studio에서 스크립트 분석이 실행되면 모든 등록된 콜백이 우선순위가 높은 순서로 호출됩니다.각 콜백은 아래에 지정된 형식에 맞는 응답 테이블을 반환하도록 의도되어 있습니다.콜백은 생성되어서는 안됩니다.
요청 테이블의 형식은 다음과 같으며, script 는 분석될 LuaSourceContainer 이다.
type Request = {script: LuaSourceContainer?}
응답 테이블에는 다음 형식이 있으며, diagnostics 는 진단 테이블의 배열입니다. 각 진단 테이블에는 아래에 나열된 항목이 있습니다.
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는 강조 표시할 줄/문자를 제공하고 강조 표시를 중지할 줄/문자를 제공하는 인터페이스 렌지를 나타냅니다. 인터페이스 렌지는 linter에서 강조 표시할 줄/문자를 제공하고 강조 표시를 중지할 줄/문자를 제공합니다.
- code는 메시지의 레이블입니다.
- message는 줄에 표시될 경고 메시지입니다.사용자가 스크립트 편집기의 줄에 커서를 놓을 때 팁에도 이 메시지가 표시됩니다.
- severity는 진단에 대한 값 Enum.Severity입니다.이는 스튜디오의 스크립트 분석 도구에서 진단이 분류되는 방법과 스크립트 편집기에서 텍스트가 강조 표시되는 방법을 결정합니다.
- 크리에이터 문서의 관련 페이지로 연결하는 링크입니다. 이 URL은 요청해야 하며, 편집기에 다른 URL이 표시되지 않습니다.
매개 변수
반환
코드 샘플
type Request = {
["script"]: LuaSourceContainer,
}
type Response = {
diagnostics: {
{
range: {
start: {
line: number,
character: number,
},
["end"]: {
line: number,
character: number,
},
},
code: string?,
message: string,
severity: Enum.Severity?,
codeDescription: { href: string }?,
}
},
}
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService:RegisterScriptAnalysisCallback("foo", 1, function(Req: Request): Response
local response = {
diagnostics = {},
}
local lineNo = 1
-- Iterate line by line
for text, newline in Req.script.Source:gmatch("([^\r\n]*)([\r\n]*)") do
local startIndex, endIndex = string.find(text, "Foo")
if startIndex and endIndex then
table.insert(response.diagnostics, {
range = {
["start"] = {
line = lineNo,
character = startIndex,
},
["end"] = {
line = lineNo,
character = endIndex,
},
},
code = "FooFinder",
message = "Foo found here!",
severity = Enum.Severity.Warning,
})
end
lineNo = lineNo + #newline:gsub("\n+", "\0%0\0"):gsub(".%z.", "."):gsub("%z", "")
end
return response
end)
OpenScriptDocumentAsync
스크립트 편집기가 지정된 스크립트를 열도록 요청하는 것.요청이 성공하면 (true, nil)을 반환합니다.요청이 실패하면 문제를 설명하는 문자열을 반환합니다(false, string).
스크립트가 이미 열려 있으면 이 함수가 성공하고 관련 편집기로 탭이 전환됩니다.
매개 변수
반환
코드 샘플
ScriptEditorService:OpenScriptDocumentAsync
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local Workspace = game:GetService("Workspace")
local newScript = Instance.new("Script")
newScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(newScript)
if success then
print("Opened script document")
else
print(`Failed to open script document: {err}`)
end
UpdateSourceAsync
지정된 스크립트에 대한 편집 시간 Script.Source을 반환합니다.
이 함수는 스크립트의 오래된 콘텐츠를 사용하여 패스된 콜백을 호출하여 스크립트의 새 콘텐츠를 계산합니다.
스크립트가 스크립트 편집기에 열려 있으면 편집기에 소스를 업데이트하도록 요청이 발생합니다.편집기는 Script.Source 속성이 사용자의 스크립트 버전과 오래되었을 경우 이 업데이트를 거부할 수 있으며, 이 경우 콜백이 다시 호출되고 시도가 반복됩니다.
콜백이 반환되지 않을 수 있습니다.콜백이 nil 를 반환하면 작업이 취소됩니다.이 함수는 작업이 취소되거나 성공할 때까지 반환됩니다.
스크립트가 편집기에서 열리지 않으면 새로운 콘텐츠가 편집기가 열릴 경우 표시할 텍스트인 스크립트 소스로 업데이트됩니다.
local ses = game:GetService('ScriptEditorService')
ses:UpdateSourceAsync(Workspace.Script, function(oldContent)
return oldContent .. " World!"
end)
매개 변수
업데이트할 스크립트 인스턴스.
새 스크립트 콘텐츠를 반환하는 함수.
반환
이벤트
TextDocumentDidChange
변경 후 바로 발생하는 화재입니다. 는 형식의 변경 구조 배열입니다:
{ range : { start : { line : number, character : number }, end : { line : number, character : number } }, text: string }
매개 변수
코드 샘플
ScriptEditorService.TextDocumentDidChange
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidChange:Connect(function(scriptDocument, changes)
print("Changed", scriptDocument, changes)
end)
TextDocumentDidClose
스크립트 편집기가 닫힐 때 바로 전에 발생하는 화재는 ScriptDocument 개체가 파괴되기 직전입니다.이 이벤트가 발생한 후, ScriptDocument 는 "닫힌" 상태에 들어가고 메서드를 호출하려고 하면 오류가 발생합니다.ScriptDocument 개체는 스크립트 편집기가 동일한 스크립트를 다시 열었더라도 재사용할 수 없습니다.
매개 변수
코드 샘플
ScriptEditorService.TextDocumentDidClose
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidClose:Connect(function(scriptDocument)
print("Closed", scriptDocument)
end)
TextDocumentDidOpen
스크립트 편집기가 열리는 즉시 서비스에 부모로 지정되고 생성된 ScriptDocument 개체에 불이 붙습니다, 이는 스크립트 편집기가 열린 직후에 발생합니다.
매개 변수
코드 샘플
ScriptEditorService.TextDocumentDidOpen
--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidOpen:Connect(function(scriptDocument)
print("Opened", scriptDocument)
end)