Last active
December 19, 2025 15:36
-
-
Save Sleitnick/ae65b6207faced16d95876cc3936ccb9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --!strict | |
| local ScriptEditorService = game:GetService("ScriptEditorService") | |
| type Request = { | |
| position: { | |
| line: number, | |
| character: number, | |
| }, | |
| textDocument: { | |
| document: ScriptDocument?, | |
| script: LuaSourceContainer?, | |
| }, | |
| } | |
| type ResponseItem = { | |
| 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, | |
| insert: { start: { line: number, character: number }, ["end"]: { line: number, character: number } }?, | |
| replace: { start: { line: number, character: number }, ["end"]: { line: number, character: number } }?, | |
| }?, | |
| } | |
| type Response = { | |
| items: { ResponseItem }, | |
| } | |
| ScriptEditorService:RegisterAutocompleteCallback("SelectionAutocomplete", 1, function(req: Request, res: Response): Response | |
| if (not req.textDocument.document) or (not req.textDocument.document:IsCommandBar()) then | |
| return res | |
| end | |
| local text = req.textDocument.document:GetLine(req.position.line) | |
| local upTo = string.sub(text, 1, req.position.character) | |
| local match = string.match(upTo, "%$(%d+)$") | |
| if not match then | |
| return res | |
| end | |
| local item: ResponseItem = { | |
| label = "Select " .. match, | |
| kind = Enum.CompletionItemKind.Snippet, | |
| tags = {Enum.CompletionItemTag.CommandLinePermissions}, | |
| detail = `game:GetService("Selection"):Get()[{match}]`, | |
| preselect = true, | |
| textEdit = { | |
| newText = `game:GetService("Selection"):Get()[{match}]`, | |
| replace = { | |
| start = { | |
| line = req.position.line, | |
| character = req.position.character - (#match + 1), | |
| }, | |
| ["end"] = { | |
| line = req.position.line, | |
| character = req.position.character, | |
| } | |
| }, | |
| }, | |
| } | |
| table.insert(res.items, item) | |
| return res | |
| end) | |
| plugin.Unloading:Connect(function() | |
| ScriptEditorService:DeregisterAutocompleteCallback("SelectionAutocomplete") | |
| end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment