[
  {
    "path": ".github/assignment.yml",
    "content": "{\n    perform: true,\n    assignees: [ chrmarti ]\n}\n"
  },
  {
    "path": ".gitignore",
    "content": "out\nnode_modules\n*.vsix"
  },
  {
    "path": ".vscode/launch.json",
    "content": "// A launch configuration that compiles the extension and then opens it inside a new window\n// Use IntelliSense to learn about possible attributes.\n// Hover to view descriptions of existing attributes.\n// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387\n{\n\t\"version\": \"0.2.0\",\n\t\"configurations\": [\n\t\t{\n\t\t\t\"name\": \"Run Extension\",\n\t\t\t\"type\": \"extensionHost\",\n\t\t\t\"request\": \"launch\",\n\t\t\t\"args\": [\n\t\t\t\t\"--extensionDevelopmentPath=${workspaceFolder}\"\n\t\t\t],\n\t\t\t\"outFiles\": [\n\t\t\t\t\"${workspaceFolder}/dist/**/*.js\"\n\t\t\t],\n\t\t\t\"preLaunchTask\": \"${defaultBuildTask}\"\n\t\t},\n\t]\n}\n"
  },
  {
    "path": ".vscode/settings.json",
    "content": "// Place your settings in this file to overwrite default and user settings.\n{\n    \"files.exclude\": {\n        \"out\": false // set this to true to hide the \"out\" folder with the compiled JS files\n    },\n    \"search.exclude\": {\n        \"out\": true // set this to false to include \"out\" folder in search results\n    },\n    // Turn off tsc task auto detection since we have the necessary tasks as npm scripts\n    \"typescript.tsc.autoDetect\": \"off\"\n}"
  },
  {
    "path": ".vscode/tasks.json",
    "content": "// See https://go.microsoft.com/fwlink/?LinkId=733558\n// for the documentation about the tasks.json format\n{\n\t\"version\": \"2.0.0\",\n\t\"tasks\": [\n\t\t{\n\t\t\t\"type\": \"npm\",\n\t\t\t\"script\": \"watch\",\n\t\t\t\"problemMatcher\": \"$tsc-watch\",\n\t\t\t\"isBackground\": true,\n\t\t\t\"presentation\": {\n\t\t\t\t\"reveal\": \"never\"\n\t\t\t},\n\t\t\t\"group\": {\n\t\t\t\t\"kind\": \"build\",\n\t\t\t\t\"isDefault\": true\n\t\t\t}\n\t\t}\n\t]\n}\n"
  },
  {
    "path": ".vscodeignore",
    "content": ".vscode/**\n.github/**\nout/test/**\ntest/**\nsrc/**\n**/*.map\n.gitignore\ntsconfig.json\n"
  },
  {
    "path": "LICENSE",
    "content": "Copyright (c) Microsoft Corporation\r\n\r\nAll rights reserved.\r\n\r\nMIT License\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation\r\nfiles (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy,\r\nmodify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software\r\nis furnished to do so, subject to the following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\r\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r\nBE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT\r\nOF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE."
  },
  {
    "path": "README.md",
    "content": "## Features\n\nShows the current regular expression's matches in a side-by-side document. This can be turned on/off with `Ctrl+Alt+M` (`⌥⌘M`).\n\nGlobal and multiline options can be added for evaluation with a side-by-side document through a status bar entry. This can be useful when the side-by-side document has multiple examples to match.\n\n![Regex Previewer in Action](images/in_action.gif)\n\n## Release Notes\n\n### 0.6.0\n\n- Add support for `d` flag in TypeScript/JavaScript (PR by [@wszgrcy](https://github.com/wszgrcy))\n\n### 0.5.0\n\n- Add chat participant\n\n### 0.4.0\n\n- Also publish as web extension\n\n### 0.3.0\n\n- Add React support (PR by [@galangel](https://github.com/galangel))\n- Add Vue support (PR by [@jombard](https://github.com/jombard))\n- Code cleanup\n\n### 0.2.0\n\n- Add PHP support (PR by [@ergunsh](https://github.com/ergunsh))\n- Add setting to disable the code lens (PR by [@ergunsh](https://github.com/ergunsh))\n- Add more sample text (PR by [@mscolnick](https://github.com/mscolnick))\n\n### 0.1.0\n\n- Status bar item to toggle adding global and multiline flags for evaluation with example text.\n- Bugfixes\n\n### 0.0.8\n\n- Add Haxe support (PR by [@Gama11](https://github.com/Gama11))\n\n### 0.0.7\n\n- Several bugfixes\n- Catch up with latest release\n\n### 0.0.6\n\n- Single toggle action to turn Regex matching on/off\n\n### 0.0.5\n\n- Make it work on Windows again...\n\n### 0.0.4\n\n- Allow any editor to show matches\n- Avoid storing sample file in installation directory\n- More bugfixes\n\n### 0.0.3\n\n- More bugfixes, make it work on Windows.\n- Add icon\n\n### 0.0.2\n\nBugfixes.\n\n### 0.0.1\n\nInitial release.\n\n## License\n\n[MIT](LICENSE)\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"regex\",\n  \"displayName\": \"Regex Previewer\",\n  \"description\": \"Regex matches previewer for JavaScript, TypeScript, PHP and Haxe in Visual Studio Code.\",\n  \"version\": \"0.6.0\",\n  \"publisher\": \"chrmarti\",\n  \"repository\": {\n    \"type\": \"git\",\n    \"url\": \"https://github.com/chrmarti/vscode-regex.git\"\n  },\n  \"license\": \"MIT\",\n  \"bugs\": {\n    \"url\": \"https://github.com/chrmarti/vscode-regex/issues\"\n  },\n  \"keywords\": [\n    \"regex\",\n    \"regular expression\",\n    \"regexp\",\n    \"test\"\n  ],\n  \"icon\": \"images/icon.png\",\n  \"engines\": {\n    \"vscode\": \"^1.92.0\"\n  },\n  \"categories\": [\n    \"Other\",\n    \"Chat\",\n    \"AI\"\n  ],\n  \"activationEvents\": [\n    \"onLanguage:javascript\",\n    \"onLanguage:javascriptreact\",\n    \"onLanguage:typescript\",\n    \"onLanguage:typescriptreact\",\n    \"onLanguage:vue\",\n    \"onLanguage:php\",\n    \"onLanguage:haxe\"\n  ],\n  \"main\": \"./out/extension\",\n  \"browser\": \"./out/extension\",\n  \"contributes\": {\n    \"configuration\": {\n      \"type\": \"object\",\n      \"title\": \"Regex Previewer Configuration\",\n      \"properties\": {\n        \"regex-previewer.enableCodeLens\": {\n          \"scope\": \"resource\",\n          \"type\": \"boolean\",\n          \"default\": true,\n          \"description\": \"Enables code lens for Regex Previewer\"\n        }\n      }\n    },\n    \"commands\": [\n      {\n        \"command\": \"extension.toggleRegexPreview\",\n        \"title\": \"Toggle Regex Preview In Side-By-Side Editors\"\n      }\n    ],\n    \"keybindings\": [\n      {\n        \"command\": \"extension.toggleRegexPreview\",\n        \"key\": \"ctrl+alt+m\",\n        \"mac\": \"cmd+alt+m\"\n      }\n    ],\n    \"chatParticipants\": [\n      {\n        \"id\": \"regex.chatParticipant\",\n        \"fullName\": \"Regex\",\n        \"name\": \"regex\",\n        \"description\": \"Talk to me about regexes!\",\n        \"isSticky\": true,\n        \"commands\": [\n          {\n            \"name\": \"new\",\n            \"description\": \"Create a new regex from a description\",\n            \"disambiguation\": [\n              {\n                \"category\": \"regex_new\",\n                \"description\": \"The user wants to create a new regex from a description.\",\n                \"examples\": [\n                  \"Create a new regex matching something\",\n                  \"New regex matching something\",\n                  \"Build a regex for something\"\n                ]\n              }\n            ]\n          },\n          {\n            \"name\": \"new-from\",\n            \"description\": \"Create a new regex from a sample\",\n            \"disambiguation\": [\n              {\n                \"category\": \"regex_new-from\",\n                \"description\": \"The user wants to create a new regex from a sample.\",\n                \"examples\": [\n                  \"Create a new regex that matches this\",\n                  \"New regex from sample\",\n                  \"Build a regex for this\"\n                ]\n              }\n            ]\n          }\n        ],\n        \"disambiguation\": [\n          {\n            \"category\": \"regex\",\n            \"description\": \"The user wants to understand a regex.\",\n            \"examples\": [\n              \"Explain this regex\",\n              \"What does this regex do?\",\n              \"How does this regex work?\"\n            ]\n          }\n        ]\n      }\n    ]\n  },\n  \"scripts\": {\n    \"vscode:prepublish\": \"yarn run compile\",\n    \"compile\": \"tsc -p ./\",\n    \"watch\": \"tsc -watch -p ./\",\n    \"package\": \"vsce package\",\n    \"publish\": \"vsce publish\"\n  },\n  \"devDependencies\": {\n    \"@types/vscode\": \"^1.92.0\",\n    \"typescript\": \"^5.6.2\"\n  }\n}"
  },
  {
    "path": "src/chat.ts",
    "content": "/*---------------------------------------------------------------------------------------------\n *  Copyright (c) Microsoft Corporation. All rights reserved.\n *  Licensed under the MIT License. See LICENSE in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\nimport * as vscode from 'vscode';\n\nconst REGEX_PARTICIPANT_ID = 'regex.chatParticipant';\n\nconst MODEL_SELECTOR: vscode.LanguageModelChatSelector = { vendor: 'copilot', family: 'gpt-4o' };\n\nexport function registerChatParticipant(context: vscode.ExtensionContext) {\n\n    const handler: vscode.ChatRequestHandler = async (request: vscode.ChatRequest, context: vscode.ChatContext, stream: vscode.ChatResponseStream, token: vscode.CancellationToken): Promise<void> => {\n        try {\n            let [model] = await vscode.lm.selectChatModels(MODEL_SELECTOR);\n            if (!model) {\n                [model] = await vscode.lm.selectChatModels();\n                if (!model) {\n                    stream.markdown('No language model available.');\n                    return;\n                }\n            }\n            const messages = [];\n            if (!request.command) {\n                for (let i = context.history.length - 1; i >= 0; i--) {\n                    const turn = context.history[i];\n                    if (turn.participant !== REGEX_PARTICIPANT_ID) {\n                        break;\n                    }\n                    if (turn instanceof vscode.ChatRequestTurn) {\n                        if (turn.command || i === 0 || context.history[i - 1].participant !== REGEX_PARTICIPANT_ID) {\n                            messages.push(...getInitialPrompt(turn).reverse());\n                            break;\n                        }\n                        messages.push(vscode.LanguageModelChatMessage.User(turn.prompt));\n                    } else if (turn instanceof vscode.ChatResponseTurn) {\n                        for (const part of turn.response) {\n                            if (part instanceof vscode.ChatResponseMarkdownPart) {\n                                messages.push(vscode.LanguageModelChatMessage.Assistant(part.value.value));\n                            }\n                        }\n                    }\n                }\n                messages.reverse();\n            }\n            if (!messages.length) {\n                messages.push(...getInitialPrompt(request));\n            } else {\n                messages.push(vscode.LanguageModelChatMessage.User(request.prompt));\n            }\n\n            const chatResponse = await model.sendRequest(messages, {}, token);\n            for await (const fragment of chatResponse.text) {\n                stream.markdown(fragment);\n            }\n        } catch (err) {\n            if (err instanceof vscode.LanguageModelError) {\n                stream.markdown(`${err.message} (${err.code})`);\n            } else {\n                throw err;\n            }\n        }\n    };\n\n    function getInitialPrompt({ prompt, command }: { prompt: string; command?: string }) {\n        const languageId = vscode.window.activeTextEditor?.document.languageId\n            || vscode.window.visibleTextEditors[0]?.document.languageId\n            || vscode.workspace.textDocuments[0]?.languageId\n            || 'javascript';\n        const languageName = languageIdToNameMapping[languageId] || languageId;\n\n        if (command === 'new') {\n            return [\n                vscode.LanguageModelChatMessage.User('You are an expert in regular expressions! Your job is to create regular expressions based on descriptions of what has to match.'),\n                vscode.LanguageModelChatMessage.User(`Create a ${languageName} regular expression that matches text with the following description: ${prompt}`),\n            ];\n        }\n        if (command === 'new-from') {\n            return [\n                vscode.LanguageModelChatMessage.User('You are an expert in regular expressions! Your job is to create regular expressions based on text samples that have to match.'),\n                vscode.LanguageModelChatMessage.User(`Create a ${languageName} regular expression that matches the following samples: ${prompt}`),\n            ];\n        }\n        return [\n            vscode.LanguageModelChatMessage.User(`You are an expert in regular expressions! Your job is to assist with regular expressions in ${languageName}.`),\n            vscode.LanguageModelChatMessage.User(prompt),\n        ]\n    }\n\n    const regex = vscode.chat.createChatParticipant(REGEX_PARTICIPANT_ID, handler);\n    regex.iconPath = vscode.Uri.joinPath(context.extensionUri, 'images', 'icon.png');\n\n    context.subscriptions.push(\n        regex,\n    );\n}\n\nconst languageIdToNameMapping: { [id: string]: string } = {\n    'javascript': 'JavaScript',\n    'javascriptreact': 'JavaScript React',\n    'typescript': 'TypeScript',\n    'typescriptreact': 'TypeScript React',\n    'vue': 'Vue',\n    'php': 'PHP',\n    'haxe': 'Haxe',\n    'python': 'Python',\n    'java': 'Java',\n    'csharp': 'C#',\n    'cpp': 'C++',\n    'ruby': 'Ruby',\n    'go': 'Go',\n    'rust': 'Rust',\n    'swift': 'Swift',\n    'kotlin': 'Kotlin',\n    'scala': 'Scala',\n    'perl': 'Perl',\n    'html': 'HTML',\n    'css': 'CSS',\n    'markdown': 'Markdown',\n    'json': 'JSON',\n    'xml': 'XML',\n    'sql': 'SQL',\n};\n"
  },
  {
    "path": "src/extension.ts",
    "content": "/*---------------------------------------------------------------------------------------------\n *  Copyright (c) Microsoft Corporation. All rights reserved.\n *  Licensed under the MIT License. See LICENSE in the project root for license information.\n *--------------------------------------------------------------------------------------------*/\n'use strict';\n\nimport * as vscode from 'vscode';\nimport { registerChatParticipant } from './chat';\n\ndeclare type IntervalToken = object;\ndeclare function setInterval(fn: () => void, delay: number): IntervalToken;\ndeclare function clearInterval(token: IntervalToken): void;\n\nexport function activate(context: vscode.ExtensionContext) {\n    registerChatParticipant(context);\n\n    const regexRegex = /(^|\\s|[()={},:?;])(\\/((?:\\\\\\/|\\[[^\\]]*\\]|[^/])+)\\/([gimuyd]*))(\\s|[()={},:?;]|$)/g;\n    const phpRegexRegex = /(^|\\s|[()={},:?;])['|\"](\\/((?:\\\\\\/|\\[[^\\]]*\\]|[^/])+)\\/([gimuy]*))['|\"](\\s|[()={},:?;]|$)/g;\n    const haxeRegexRegex = /(^|\\s|[()={},:?;])(~\\/((?:\\\\\\/|\\[[^\\]]*\\]|[^/])+)\\/([gimsu]*))(\\s|[.()={},:?;]|$)/g;\n    const regexHighlight = vscode.window.createTextEditorDecorationType({ backgroundColor: 'rgba(100,100,100,.35)' });\n    const matchHighlight = vscode.window.createTextEditorDecorationType({ backgroundColor: 'rgba(255,255,0,.35)' });\n\n    const matchesFileContent = `Lorem ipsum dolor sit amet, consectetur adipiscing elit,\nsed do eiusmod tempor incididunt ut labore et dolore magna\naliqua. Ut enim ad minim veniam, quis nostrud exercitation\nullamco laboris nisi ut aliquip ex ea commodo consequat.\nDuis aute irure dolor in reprehenderit in voluptate velit\nesse cillum dolore eu fugiat nulla pariatur. Excepteur sint\noccaecat cupidatat non proident, sunt in culpa qui officia\ndeserunt mollit anim id est laborum.\n\nabcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ\n0123456789 _+-.,!@#$%^&*();\\/|<>\"'\n12345 -98.7 3.141 .6180 9,000 +42\n555.123.4567\t+1-(800)-555-2468\nfoo@demo.net\tbar.ba@test.co.uk\nwww.demo.com\thttp://foo.co.uk/\nhttps://marketplace.visualstudio.com/items?itemName=chrmarti.regex\nhttps://github.com/chrmarti/vscode-regex\n`;\n    const languages = ['javascript', 'javascriptreact', 'typescript', 'typescriptreact', 'vue', 'php', 'haxe'];\n\n    const decorators = new Map<vscode.TextEditor, RegexMatchDecorator>();\n\n    context.subscriptions.push(vscode.commands.registerCommand('extension.toggleRegexPreview', toggleRegexPreview));\n\n    languages.forEach(language => {\n        context.subscriptions.push(vscode.languages.registerCodeLensProvider(language, { provideCodeLenses }));\n    });\n\n    context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(() => updateDecorators(findRegexEditor())));\n\n    const interval = setInterval(() => updateDecorators(), 5000);\n    context.subscriptions.push({ dispose: () => clearInterval(interval) });\n\n    function provideCodeLenses(document: vscode.TextDocument, token: vscode.CancellationToken) {\n        const config = vscode.workspace.getConfiguration('regex-previewer', document.uri);\n        if (!config.enableCodeLens) return;\n\n        const matches = findRegexes(document);\n        return matches.map(match => new vscode.CodeLens(match.range, {\n            title: 'Test Regex...',\n            command: 'extension.toggleRegexPreview',\n            arguments: [ match ]\n        }));\n    }\n\n    let addGMEnabled = false;\n    const toggleGM = vscode.window.createStatusBarItem();\n    toggleGM.command = 'regexpreview.toggleGM';\n    context.subscriptions.push(toggleGM);\n    context.subscriptions.push(vscode.commands.registerCommand('regexpreview.toggleGM', () => {\n        addGMEnabled = !addGMEnabled;\n        updateToggleGM();\n        for (const decorator of decorators.values()) {\n            decorator.update();\n        }\n    }))\n    function updateToggleGM() {\n        toggleGM.text = addGMEnabled ? 'Adding /gm' : 'Not adding /gm';\n        toggleGM.tooltip = addGMEnabled ? 'Click to stop adding global and multiline (/gm) options to regexes for evaluation with example text.' : 'Click to add global and multiline (/gm) options to regexes for evaluation with example text.'\n    }\n    updateToggleGM();\n    function addGM(regex: RegExp) {\n        if (!addGMEnabled || (regex.global && regex.multiline)) {\n            return regex;\n        }\n\n        let flags = regex.flags;\n        if (!regex.global) {\n            flags += 'g';\n        }\n        if (!regex.multiline) {\n            flags += 'm';\n        }\n        return new RegExp(regex.source, flags);\n    }\n\n    let enabled = false;\n    function toggleRegexPreview(initialRegexMatch?: RegexMatch) {\n        enabled = !enabled || !!initialRegexMatch && !!initialRegexMatch.regex;\n        toggleGM[enabled ? 'show' : 'hide']();\n        if (enabled) {\n            const visibleEditors = getVisibleTextEditors();\n            if (visibleEditors.length === 1) {\n                return openLoremIpsum(visibleEditors[0].viewColumn! + 1, initialRegexMatch);\n            } else {\n                updateDecorators(findRegexEditor(), initialRegexMatch);\n            }\n        } else {\n            decorators.forEach(decorator => decorator.dispose());\n        }\n    }\n\n    function openLoremIpsum(column: number, initialRegexMatch?: RegexMatch) {\n        return vscode.workspace.openTextDocument({ language: 'text', content: matchesFileContent })\n            .then(document => {\n                return vscode.window.showTextDocument(document, column, true);\n            }).then(editor => {\n                updateDecorators(findRegexEditor(), initialRegexMatch);\n            }).then(undefined, reason => {\n                vscode.window.showErrorMessage(reason);\n            });\n    }\n\n    function updateDecorators(regexEditor?: vscode.TextEditor, initialRegexMatch?: RegexMatch) {\n        if (!enabled) {\n            return;\n        }\n\n        // TODO: figure out why originEditor.document is sometimes a different object\n        if (regexEditor && initialRegexMatch && initialRegexMatch.document && initialRegexMatch.document.uri.toString() === regexEditor.document.uri.toString()) {\n            initialRegexMatch.document = regexEditor.document;\n        }\n\n        const remove = new Map(decorators);\n        getVisibleTextEditors().forEach(editor => {\n            remove.delete(editor);\n            applyDecorator(editor, regexEditor, initialRegexMatch);\n        });\n        remove.forEach(decorator => decorator.dispose());\n    }\n\n    function getVisibleTextEditors() {\n        return vscode.window.visibleTextEditors.filter(editor => typeof editor.viewColumn === 'number');\n    }\n\n    function applyDecorator(matchEditor: vscode.TextEditor, initialRegexEditor?: vscode.TextEditor, initialRegexMatch?: RegexMatch) {\n        let decorator = decorators.get(matchEditor);\n        const newDecorator = !decorator;\n        if (newDecorator) {\n            decorator = new RegexMatchDecorator(matchEditor);\n            context.subscriptions.push(decorator);\n            decorators.set(matchEditor, decorator);\n        }\n        if (newDecorator || initialRegexEditor || initialRegexMatch) {\n            decorator!.apply(initialRegexEditor, initialRegexMatch);\n        }\n    }\n\n    function discardDecorator(matchEditor: vscode.TextEditor) {\n        decorators.delete(matchEditor);\n    }\n\n    interface RegexMatch {\n\n        document: vscode.TextDocument;\n\n        regex: RegExp;\n\n        range: vscode.Range;\n\n    }\n\n    interface Match {\n\n        range: vscode.Range;\n    }\n\n    class RegexMatchDecorator {\n\n        private stableRegexEditor?: vscode.TextEditor;\n        private stableRegexMatch?: RegexMatch;\n        private disposables: vscode.Disposable[] = [];\n\n        constructor(private matchEditor: vscode.TextEditor) {\n\n            this.disposables.push(vscode.workspace.onDidCloseTextDocument(e => {\n                if (this.stableRegexEditor && e === this.stableRegexEditor.document) {\n                    this.stableRegexEditor = undefined;\n                    this.stableRegexMatch = undefined;\n                    matchEditor.setDecorations(matchHighlight, []);\n                } else if (e === matchEditor.document) {\n                    this.dispose();\n                }\n            }));\n\n            this.disposables.push(vscode.workspace.onDidChangeTextDocument(e => {\n                if ((this.stableRegexEditor && e.document === this.stableRegexEditor.document) || e.document === matchEditor.document) {\n                    this.update();\n                }\n            }));\n\n            this.disposables.push(vscode.window.onDidChangeTextEditorSelection(e => {\n                if (this.stableRegexEditor && e.textEditor === this.stableRegexEditor) {\n                    this.stableRegexMatch = undefined;\n                    this.update();\n                }\n            }));\n\n            this.disposables.push(vscode.window.onDidChangeActiveTextEditor(e => {\n                this.update();\n            }));\n\n            this.disposables.push({ dispose: () => {\n                matchEditor.setDecorations(matchHighlight, []);\n                matchEditor.setDecorations(regexHighlight, []);\n            }});\n        }\n\n        public apply(stableRegexEditor?: vscode.TextEditor, stableRegexMatch?: RegexMatch) {\n            this.stableRegexEditor = stableRegexEditor;\n            this.stableRegexMatch = stableRegexMatch;\n            this.update();\n        }\n\n        public dispose() {\n            discardDecorator(this.matchEditor);\n            this.disposables.forEach(disposable => {\n                disposable.dispose();\n            });\n        }\n\n        public update() {\n            const regexEditor = this.stableRegexEditor = findRegexEditor() || this.stableRegexEditor;\n            let regex = regexEditor && findRegexAtCaret(regexEditor);\n            if (this.stableRegexMatch) {\n                if (regex || !regexEditor || regexEditor.document !== this.stableRegexMatch.document) {\n                    this.stableRegexMatch = undefined;\n                } else {\n                    regex = this.stableRegexMatch;\n                }\n            }\n            const matches = regex && regexEditor !== this.matchEditor ? findMatches(regex, this.matchEditor.document) : [];\n            this.matchEditor.setDecorations(matchHighlight, matches.map(match => match.range));\n\n            if (regexEditor) {\n                regexEditor.setDecorations(regexHighlight, (this.stableRegexMatch || regexEditor !== vscode.window.activeTextEditor) && regex ? [ regex.range ] : []);\n            }\n        }\n    }\n\n    function findRegexEditor() {\n        const activeEditor = vscode.window.activeTextEditor;\n        if (!activeEditor || languages.indexOf(activeEditor.document.languageId) === -1) {\n            return undefined;\n        }\n        return activeEditor;\n    }\n\n    function findRegexAtCaret(editor: vscode.TextEditor): RegexMatch | undefined {\n        const anchor = editor.selection.anchor;\n        const line = editor.document.lineAt(anchor);\n        const text = line.text.substr(0, 1000);\n\n        let match: RegExpExecArray | null;\n        let regex = getRegexRegex(editor.document.languageId);\n        regex.lastIndex = 0;\n        while ((match = regex.exec(text)) && (match.index + match[1].length + match[2].length < anchor.character));\n        if (match && match.index + match[1].length <= anchor.character) {\n            return createRegexMatch(editor.document, anchor.line, match);\n        }\n    }\n\n    function findRegexes(document: vscode.TextDocument) {\n        const matches: RegexMatch[] = [];\n        for (let i = 0; i < document.lineCount; i++) {\n            const line = document.lineAt(i);\n            let match: RegExpExecArray | null;\n            let regex = getRegexRegex(document.languageId);\n            regex.lastIndex = 0;\n            const text = line.text.substr(0, 1000);\n            while ((match = regex.exec(text))) {\n                const result = createRegexMatch(document, i, match);\n                if (result) {\n                    matches.push(result);\n                }\n            }\n        }\n        return matches;\n    }\n\n    function getRegexRegex(languageId: String) {\n        if (languageId == 'haxe') {\n            return haxeRegexRegex;\n        } else if (languageId == 'php') {\n            return phpRegexRegex;\n        }\n        return regexRegex;\n    }\n\n    function createRegexMatch(document: vscode.TextDocument, line: number, match: RegExpExecArray) {\n        const regex = createRegex(match[3], match[4]);\n        if (regex) {\n            return {\n                document: document,\n                regex: regex,\n                range: new vscode.Range(line, match.index + match[1].length, line, match.index + match[1].length + match[2].length)\n            };\n        }\n    }\n\n    function createRegex(pattern: string, flags: string) {\n            try {\n                return new RegExp(pattern, flags);\n            } catch (e) {\n                // discard\n            }\n    }\n\n    function findMatches(regexMatch: RegexMatch, document: vscode.TextDocument) {\n        const text = document.getText();\n        const matches: Match[] = [];\n        const regex = addGM(regexMatch.regex);\n        let match: RegExpExecArray | null;\n        while ((regex.global || !matches.length) && (match = regex.exec(text))) {\n            matches.push({\n                range: new vscode.Range(document.positionAt(match.index), document.positionAt(match.index + match[0].length))\n            });\n            // Handle empty matches (fixes #4)\n            if (regex.lastIndex === match.index) {\n                regex.lastIndex++;\n            }\n        }\n        return matches;\n    }\n}\n"
  },
  {
    "path": "tsconfig.json",
    "content": "{\n\t\"compilerOptions\": {\n\t\t\"module\": \"commonjs\",\n\t\t\"target\": \"ES2022\",\n\t\t\"lib\": [\n\t\t\t\"ES2022\"\n\t\t],\n\t\t\"outDir\": \"out\",\n\t\t\"sourceMap\": true,\n\t\t\"rootDir\": \"src\",\n\t\t\"strict\": true\n\t},\n\t\"exclude\": [\n\t\t\"node_modules\"\n\t]\n}"
  }
]