Help with ScriptEditorService

How do I use the auto complete API? I find the documentation very confusing and it literally makes no sense. I want to integrate this into my own plugin so I can work faster. If you could help, then thanks!

What are you trying to do with your plugin?

I’m trying to use the new script editor api to create my own autocomplete.

The documentation is basically saying it’s taking in a table called which they called “Request” and a table they called “Response” which returns a table.

Let me mess around with it and see if I can get it.

Here’s the code sample they provided on the Wiki for it:

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)

Edit: Just tried getting a little snippet plugin to work and make an object for me.
ScriptEditorService: Parsing failed with error Failed to read key "kind", value is not an object, but string, sending default response
Now I get this error every time I type and it renders the autocomplete window.

I was able to figure it out, here is a working example:
ScriptEditorService.Instance.RegisterScriptEditorContext(
“ScriptEditorServiceTest”,
new ScriptEditorContext
{
Keywords = new[] { “hello”, “world” },
GetCurrentText = () => “ScriptEditorServiceTest is working!”,
GetCompletionItems = ScriptEditorService.GetCompletionItemsForScriptEditorContext,
});

This creates an auto complete context that can be used like this:
ScriptEditorService.Instance.PushScriptEditorContext(“ScriptEditorServiceTest”);
ScriptEditorService.Instance.RemoveScriptEditorContext(“ScriptEditorServiceTest”);