A Regex file extension that makes it way easier to edit large regex.
have regex file icon
4 files changed, +315 -194
+15-0icon-theme.json
| @@ -0,0 +1,15 @@ | ||
| 1 | +{ | |
| 2 | + "iconDefinitions": { | |
| 3 | + "regexFileIcon": { | |
| 4 | + "iconPath": "./images/regex-icon.svg" | |
| 5 | + } | |
| 6 | + }, | |
| 7 | + "fileExtensions": { | |
| 8 | + "re": "regexFileIcon", | |
| 9 | + "regex": "regexFileIcon" | |
| 10 | + }, | |
| 11 | + "fileNames": { | |
| 12 | + ".re": "regexFileIcon", | |
| 13 | + ".regex": "regexFileIcon" | |
| 14 | + } | |
| 15 | +} |
+94-0images/regex-icon.svg
| @@ -0,0 +1,94 @@ | ||
| 1 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
| 2 | +<!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --> | |
| 3 | + | |
| 4 | +<svg | |
| 5 | + width="800px" | |
| 6 | + height="800px" | |
| 7 | + viewBox="0 0 48 48" | |
| 8 | + version="1.1" | |
| 9 | + id="svg18" | |
| 10 | + sodipodi:docname="regex-icon.svg" | |
| 11 | + inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)" | |
| 12 | + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" | |
| 13 | + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" | |
| 14 | + xmlns="http://www.w3.org/2000/svg" | |
| 15 | + xmlns:svg="http://www.w3.org/2000/svg"> | |
| 16 | + <sodipodi:namedview | |
| 17 | + id="namedview20" | |
| 18 | + pagecolor="#ffffff" | |
| 19 | + bordercolor="#666666" | |
| 20 | + borderopacity="1.0" | |
| 21 | + inkscape:pageshadow="2" | |
| 22 | + inkscape:pageopacity="0.0" | |
| 23 | + inkscape:pagecheckerboard="0" | |
| 24 | + showgrid="false" | |
| 25 | + inkscape:zoom="0.97375" | |
| 26 | + inkscape:cx="399.48652" | |
| 27 | + inkscape:cy="400" | |
| 28 | + inkscape:window-width="1588" | |
| 29 | + inkscape:window-height="991" | |
| 30 | + inkscape:window-x="26" | |
| 31 | + inkscape:window-y="23" | |
| 32 | + inkscape:window-maximized="0" | |
| 33 | + inkscape:current-layer="svg18" /> | |
| 34 | + <defs | |
| 35 | + id="defs4"> | |
| 36 | + <style | |
| 37 | + id="style2">.a{fill:none;stroke:#000000;stroke-linecap:round;stroke-linejoin:round;}</style> | |
| 38 | + </defs> | |
| 39 | + <path | |
| 40 | + class="a" | |
| 41 | + d="M15.88,8.4H6.5a2,2,0,0,0-2,2V37.6a2,2,0,0,0,2,2h9.38" | |
| 42 | + id="path6" /> | |
| 43 | + <path | |
| 44 | + class="a" | |
| 45 | + d="M32.12,39.6H41.5a2,2,0,0,0,2-2V10.4a2,2,0,0,0-2-2H32.12" | |
| 46 | + id="path8" /> | |
| 47 | + <line | |
| 48 | + class="a" | |
| 49 | + x1="28.34" | |
| 50 | + y1="30.45" | |
| 51 | + x2="28.34" | |
| 52 | + y2="14.79" | |
| 53 | + id="line10" /> | |
| 54 | + <line | |
| 55 | + class="a" | |
| 56 | + x1="21.56" | |
| 57 | + y1="26.54" | |
| 58 | + x2="35.12" | |
| 59 | + y2="18.71" | |
| 60 | + id="line12" /> | |
| 61 | + <line | |
| 62 | + class="a" | |
| 63 | + x1="35.12" | |
| 64 | + y1="26.54" | |
| 65 | + x2="21.56" | |
| 66 | + y2="18.71" | |
| 67 | + id="line14" /> | |
| 68 | + <circle | |
| 69 | + class="a" | |
| 70 | + cx="15.33" | |
| 71 | + cy="30.45" | |
| 72 | + r="2.5" | |
| 73 | + id="circle16" /> | |
| 74 | + <path | |
| 75 | + style="fill:#00ff00;stroke-width:1.02696" | |
| 76 | + d="M 97.23686,666.9452 C 82.622518,663.01233 70.6304,650.1218 67.393457,634.86601 c -1.64416,-7.74896 -1.64416,-461.98306 0,-469.73202 2.343308,-11.04407 10.456746,-22.44794 19.91407,-27.9903 9.754773,-5.71668 9.348866,-5.69311 98.045583,-5.69311 89.13722,0 85.05514,-0.26707 87.32893,5.71347 1.20422,3.16734 -0.58888,8.31831 -3.47041,9.96931 -1.67122,0.95754 -22.29149,1.3859 -85.46755,1.7755 l -83.26491,0.51348 -5.026299,3.10802 c -3.114694,1.92597 -6.208348,5.01993 -8.134323,8.13512 l -3.108022,5.02711 V 400 634.30741 l 3.108022,5.0271 c 1.925975,3.11519 5.019629,6.20916 8.134323,8.13513 l 5.026299,3.10802 83.26491,0.51348 c 63.17606,0.3896 83.79633,0.81796 85.46755,1.7755 2.88153,1.651 4.67463,6.80197 3.47041,9.9693 -2.27606,5.98652 1.87417,5.71964 -87.80143,5.6459 -67.89053,-0.0559 -83.13431,-0.32309 -87.64375,-1.53664 z" | |
| 77 | + id="path355" | |
| 78 | + transform="scale(0.06)" /> | |
| 79 | + <path | |
| 80 | + style="fill:#00ff00;stroke-width:1.02696" | |
| 81 | + d="m 530.5873,666.90536 c -4.84862,-3.39612 -4.73671,-11.20957 0.20108,-14.03872 1.67122,-0.95754 22.29148,-1.3859 85.46754,-1.7755 l 83.2649,-0.51348 5.02631,-3.10802 c 3.11469,-1.92597 6.20835,-5.01994 8.13432,-8.13513 l 3.10802,-5.0271 V 400 165.69259 l -3.10802,-5.02711 c -1.92597,-3.11519 -5.01963,-6.20915 -8.13432,-8.13512 l -5.02631,-3.10802 -83.2649,-0.51348 c -63.17606,-0.3896 -83.79632,-0.81796 -85.46754,-1.7755 -2.88154,-1.651 -4.67465,-6.80197 -3.47043,-9.96931 2.2738,-5.98054 -1.80828,-5.71347 87.32894,-5.71347 88.69672,0 88.2908,-0.0236 98.04559,5.69311 9.45731,5.54236 17.57076,16.94623 19.91406,27.9903 1.64416,7.74896 1.64416,461.98306 0,469.73202 -2.3433,11.04407 -10.45675,22.44794 -19.91406,27.99031 -9.75479,5.71667 -9.34887,5.6931 -98.04559,5.6931 -73.26032,0 -81.95514,-0.17005 -84.05959,-1.64406 z" | |
| 82 | + id="path394" | |
| 83 | + transform="scale(0.06)" /> | |
| 84 | + <path | |
| 85 | + style="fill:#00ff00;stroke-width:1.02696" | |
| 86 | + d="m 470.1971,515.77293 c -1.21187,-0.19521 -3.06039,-1.30164 -4.10783,-2.45871 -1.79544,-1.98339 -1.9338,-5.50701 -2.4179,-61.57603 l -0.51348,-59.47226 -47.24005,27.3135 c -54.16073,31.31494 -54.05085,31.25497 -57.27507,31.25497 -5.39141,0 -9.4872,-7.40189 -6.77974,-12.25233 1.02794,-1.84157 16.74047,-11.45912 52.01927,-31.84069 27.80055,-16.06117 50.52837,-29.46297 50.50626,-29.78177 -0.0221,-0.3188 -22.46128,-13.47924 -49.86483,-29.24542 -27.40355,-15.76618 -50.72308,-29.80797 -51.82117,-31.20396 -2.66075,-3.3826 -2.5182,-6.67496 0.43778,-10.1115 4.64605,-5.40135 5.20464,-5.1558 58.66967,25.79084 27.11168,15.69279 49.87163,28.7544 50.57767,29.0258 1.01781,0.39126 1.28369,-11.76932 1.28369,-58.71315 V 243.2956 l 2.52072,-2.52071 c 2.48062,-2.48062 6.69768,-3.25371 10.27025,-1.88279 4.56298,1.75098 4.66731,3.19325 4.66731,64.52288 0,31.94076 0.25205,58.07411 0.56012,58.07411 0.30805,0 23.068,-13.0202 50.57766,-28.93378 54.26482,-31.39071 54.719,-31.59072 59.39325,-26.15658 2.94396,3.42255 3.09982,6.72726 0.47469,10.06457 -1.07779,1.37019 -24.40487,15.41197 -51.83796,31.20397 -27.43309,15.79199 -49.88888,28.99115 -49.90174,29.33149 -0.0128,0.34032 22.27442,13.44706 49.52731,29.12608 27.25289,15.67901 50.5905,29.63685 51.86136,31.01742 1.27086,1.38058 2.31065,3.67525 2.31065,5.09927 0,3.37098 -5.20994,8.59287 -8.5732,8.59287 -1.495,0 -23.75167,-12.22626 -53.22406,-29.23756 l -50.6546,-29.23758 -0.51348,59.37578 c -0.4047,46.79804 -0.79804,59.7185 -1.85679,60.99359 -1.66967,2.01083 -6.15388,3.51497 -9.07576,3.0443 z" | |
| 87 | + id="path433" | |
| 88 | + transform="scale(0.06)" /> | |
| 89 | + <path | |
| 90 | + style="fill:#00ff00;stroke-width:1.02696" | |
| 91 | + d="m 242.99084,556.01484 c -22.28696,-5.99371 -37.47912,-25.77952 -37.39167,-48.69777 0.052,-13.62608 4.20759,-24.14912 13.46785,-34.10412 19.31005,-20.75876 51.72091,-21.12144 72.06213,-0.80638 5.98015,5.97246 11.45657,15.7132 13.2762,23.61397 2.55006,11.07224 0.63383,25.14202 -4.8149,35.35316 -3.56801,6.6866 -13.64825,16.76684 -20.33485,20.33485 -10.75765,5.74035 -24.75287,7.40223 -36.26476,4.30629 z m 26.78567,-18.73393 c 11.29004,-5.53654 17.53882,-15.39379 18.11927,-28.58257 0.32462,-7.3758 0.0336,-9.12118 -2.43926,-14.63155 -3.22413,-7.18432 -9.54526,-13.56221 -16.72669,-16.87689 -7.36786,-3.40073 -20.38694,-3.09371 -27.6172,0.65127 -7.08852,3.67157 -12.28167,9.01954 -15.57238,16.03664 -2.24346,4.78393 -2.67386,7.10202 -2.59062,13.95274 0.10831,8.91464 1.34449,12.68082 6.48233,19.74914 3.45782,4.75705 9.13444,8.93034 15.1921,11.16881 6.02152,2.22511 19.18904,1.45681 25.15245,-1.46759 z" | |
| 92 | + id="path472" | |
| 93 | + transform="scale(0.06)" /> | |
| 94 | +</svg> |
+9-5package.json
| @@ -18,10 +18,6 @@ | ||
| 18 | 18 | "main": "./dist/extension.js", |
| 19 | 19 | "contributes": { |
| 20 | 20 | "commands": [ |
| 21 | - { | |
| 22 | - "command": "regex-file.helloWorld", | |
| 23 | - "title": "Hello World" | |
| 24 | - }, | |
| 25 | 21 | { |
| 26 | 22 | "command": "regex-file.showButtons", |
| 27 | 23 | "title": "Show Buttons" |
| @@ -42,10 +38,18 @@ | ||
| 42 | 38 | "Regex" |
| 43 | 39 | ], |
| 44 | 40 | "extensions": [ |
| 45 | - ".re" | |
| 41 | + ".re", | |
| 42 | + ".regex" | |
| 46 | 43 | ] |
| 47 | 44 | } |
| 48 | 45 | ], |
| 46 | + "iconThemes": [ | |
| 47 | + { | |
| 48 | + "id": "regex-file-icons", | |
| 49 | + "label": "Regex File Icons", | |
| 50 | + "path": "./icon-theme.json" | |
| 51 | + } | |
| 52 | + ], | |
| 49 | 53 | "configuration": { |
| 50 | 54 | "properties": { |
| 51 | 55 | "regex-file.flags": { |
+197-189src/extension.ts
| @@ -2,14 +2,14 @@ import * as vscode from "vscode"; | ||
| 2 | 2 | |
| 3 | 3 | /* GLOBAL CONSTANTS */ |
| 4 | 4 | const timeout = vscode.workspace |
| 5 | - .getConfiguration("yourExtension") | |
| 6 | - .get("timeout", 1000); | |
| 5 | + .getConfiguration("yourExtension") | |
| 6 | + .get("timeout", 1000); | |
| 7 | 7 | const maxMatches = vscode.workspace |
| 8 | - .getConfiguration("yourExtension") | |
| 9 | - .get("maxMatches", 10000); | |
| 8 | + .getConfiguration("yourExtension") | |
| 9 | + .get("maxMatches", 10000); | |
| 10 | 10 | const baseEditorStyle = vscode.window.createTextEditorDecorationType({ |
| 11 | - backgroundColor: "yellow", | |
| 12 | - color: "black", | |
| 11 | + backgroundColor: "yellow", | |
| 12 | + color: "black", | |
| 13 | 13 | }); |
| 14 | 14 | |
| 15 | 15 | /* GLOBAL VARIABLES */ |
| @@ -22,252 +22,260 @@ const flagButtons: { [key: string]: InnerMapValue } = {}; | ||
| 22 | 22 | |
| 23 | 23 | /* TYPES */ |
| 24 | 24 | type GroupMatches = { |
| 25 | - style: vscode.TextEditorDecorationType; | |
| 26 | - matches: vscode.Range[]; | |
| 25 | + style: vscode.TextEditorDecorationType; | |
| 26 | + matches: vscode.Range[]; | |
| 27 | 27 | }; |
| 28 | 28 | type GroupMatchMap = { |
| 29 | - [key: string]: GroupMatches; | |
| 29 | + [key: string]: GroupMatches; | |
| 30 | 30 | }; |
| 31 | 31 | interface InnerMapValue { |
| 32 | - state: "on" | "off"; | |
| 33 | - button: vscode.StatusBarItem; | |
| 32 | + state: "on" | "off"; | |
| 33 | + button: vscode.StatusBarItem; | |
| 34 | 34 | } |
| 35 | 35 | const states: Record<"on" | "off", string> = { |
| 36 | - on: "$(check)", | |
| 37 | - off: "$(x)", | |
| 36 | + on: "$(check)", | |
| 37 | + off: "$(x)", | |
| 38 | 38 | }; |
| 39 | 39 | |
| 40 | 40 | function getConfigFlags(): string { |
| 41 | - const config = vscode.workspace.getConfiguration("regex-file"); | |
| 42 | - return config.get("flags") as string; | |
| 41 | + const config = vscode.workspace.getConfiguration("regex-file"); | |
| 42 | + return config.get("flags") as string; | |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | function getRandomColor() { |
| 46 | - // Generate a random hex color | |
| 47 | - const letters = "0123456789ABCDEF"; | |
| 48 | - let color = "#"; | |
| 49 | - for (let i = 0; i < 6; i++) { | |
| 50 | - color += letters[Math.floor(Math.random() * 16)]; | |
| 51 | - } | |
| 52 | - return color; | |
| 46 | + // Generate a random hex color | |
| 47 | + const letters = "0123456789ABCDEF"; | |
| 48 | + let color = "#"; | |
| 49 | + for (let i = 0; i < 6; i++) { | |
| 50 | + color += letters[Math.floor(Math.random() * 16)]; | |
| 51 | + } | |
| 52 | + return color; | |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | function getReEditor(): vscode.TextEditor | undefined { |
| 56 | - const editors = vscode.window.visibleTextEditors; | |
| 56 | + const editors = vscode.window.visibleTextEditors; | |
| 57 | 57 | |
| 58 | - for (const editor of editors) { | |
| 59 | - const fileName = editor.document.fileName; | |
| 60 | - if (fileName.endsWith(".re")) { | |
| 61 | - return editor; | |
| 58 | + for (const editor of editors) { | |
| 59 | + const fileName = editor.document.fileName; | |
| 60 | + if (fileName.endsWith(".re")) { | |
| 61 | + return editor; | |
| 62 | + } | |
| 62 | 63 | } |
| 63 | - } | |
| 64 | - console.log("No regex document."); | |
| 64 | + console.log("No regex document."); | |
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | function getTextEditor(): vscode.TextEditor | undefined { |
| 68 | - const editors = vscode.window.visibleTextEditors; | |
| 68 | + const editors = vscode.window.visibleTextEditors; | |
| 69 | 69 | |
| 70 | - for (const editor of editors) { | |
| 71 | - const fileName = editor.document.fileName; | |
| 72 | - if (!fileName.endsWith(".re")) { | |
| 73 | - return editor; | |
| 70 | + for (const editor of editors) { | |
| 71 | + const fileName = editor.document.fileName; | |
| 72 | + if (!fileName.endsWith(".re")) { | |
| 73 | + return editor; | |
| 74 | + } | |
| 74 | 75 | } |
| 75 | - } | |
| 76 | - console.log("No search document."); | |
| 76 | + console.log("No search document."); | |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | export function activate(context: vscode.ExtensionContext) { |
| 80 | - outputChannel = vscode.window.createOutputChannel("regex-file"); | |
| 81 | - createFlagButtons(context); | |
| 82 | - highlightMatches(); | |
| 83 | - vscode.window.onDidChangeVisibleTextEditors(highlightMatches); | |
| 84 | - vscode.workspace.onDidChangeTextDocument(highlightMatches); | |
| 80 | + outputChannel = vscode.window.createOutputChannel("regex-file"); | |
| 81 | + createFlagButtons(context); | |
| 82 | + highlightMatches(); | |
| 83 | + vscode.window.onDidChangeVisibleTextEditors(highlightMatches); | |
| 84 | + vscode.workspace.onDidChangeTextDocument(highlightMatches); | |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | function createFlagButtons(context: vscode.ExtensionContext): void { |
| 88 | - ["g", "i", "m", "s", "u", "y", "x"].forEach((flag) => { | |
| 89 | - const button = vscode.window.createStatusBarItem( | |
| 90 | - vscode.StatusBarAlignment.Left | |
| 91 | - ); | |
| 92 | - let state: "on" | "off" = "off"; | |
| 93 | - if (getConfigFlags().includes(flag)) { | |
| 94 | - state = "on"; | |
| 95 | - } | |
| 96 | - button.text = `${states[state]} ${flag.toUpperCase()}`; | |
| 97 | - button.tooltip = `Toggle ${flag} flag`; | |
| 98 | - button.command = `regex.toggleFlag${flag.toUpperCase()}`; | |
| 99 | - button.show(); | |
| 100 | - flagButtons[flag] = { | |
| 101 | - state, | |
| 102 | - button, | |
| 103 | - }; | |
| 104 | - let disposable = vscode.commands.registerCommand( | |
| 105 | - `regex.toggleFlag${flag.toUpperCase()}`, | |
| 106 | - () => { | |
| 107 | - toggleFlag(flag); | |
| 108 | - } | |
| 109 | - ); | |
| 110 | - context.subscriptions.push(button); | |
| 111 | - context.subscriptions.push(disposable); | |
| 112 | - }); | |
| 88 | + ["g", "i", "m", "s", "u", "y", "x"].forEach((flag) => { | |
| 89 | + const button = vscode.window.createStatusBarItem( | |
| 90 | + vscode.StatusBarAlignment.Left | |
| 91 | + ); | |
| 92 | + let state: "on" | "off" = "off"; | |
| 93 | + if (getConfigFlags().includes(flag)) { | |
| 94 | + state = "on"; | |
| 95 | + } | |
| 96 | + button.text = `${states[state]} ${flag.toUpperCase()}`; | |
| 97 | + button.tooltip = `Toggle ${flag} flag`; | |
| 98 | + button.command = `regex.toggleFlag${flag.toUpperCase()}`; | |
| 99 | + button.show(); | |
| 100 | + flagButtons[flag] = { | |
| 101 | + state, | |
| 102 | + button, | |
| 103 | + }; | |
| 104 | + let disposable = vscode.commands.registerCommand( | |
| 105 | + `regex.toggleFlag${flag.toUpperCase()}`, | |
| 106 | + () => { | |
| 107 | + toggleFlag(flag); | |
| 108 | + } | |
| 109 | + ); | |
| 110 | + context.subscriptions.push(button); | |
| 111 | + context.subscriptions.push(disposable); | |
| 112 | + }); | |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | function getRegexFlags(): [string, boolean] { |
| 116 | - let flags = ""; | |
| 117 | - let hasX = false; | |
| 118 | - Object.entries(flagButtons).forEach(([flag, info]) => { | |
| 119 | - if (info.state === "on") { | |
| 120 | - if (flag === "x") { | |
| 121 | - hasX = true; | |
| 122 | - } else { | |
| 123 | - flags += flag; | |
| 124 | - } | |
| 125 | - } | |
| 126 | - }); | |
| 127 | - return [flags, hasX]; | |
| 116 | + let flags = ""; | |
| 117 | + let hasX = false; | |
| 118 | + Object.entries(flagButtons).forEach(([flag, info]) => { | |
| 119 | + if (info.state === "on") { | |
| 120 | + if (flag === "x") { | |
| 121 | + hasX = true; | |
| 122 | + } else { | |
| 123 | + flags += flag; | |
| 124 | + } | |
| 125 | + } | |
| 126 | + }); | |
| 127 | + return [flags, hasX]; | |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | function applyGroupMatchDecorations( |
| 131 | - editor: vscode.TextEditor, | |
| 132 | - groupMatches: GroupMatchMap | |
| 131 | + editor: vscode.TextEditor, | |
| 132 | + groupMatches: GroupMatchMap | |
| 133 | 133 | ) { |
| 134 | - for (const groupName of Object.keys(groupMatches)) { | |
| 135 | - const { style, matches } = groupMatches[groupName]; | |
| 136 | - textDecorations.push(style); | |
| 134 | + for (const groupName of Object.keys(groupMatches)) { | |
| 135 | + const { style, matches } = groupMatches[groupName]; | |
| 136 | + textDecorations.push(style); | |
| 137 | 137 | |
| 138 | - const decorations: vscode.DecorationOptions[] = matches.map((range) => ({ | |
| 139 | - range, | |
| 140 | - hoverMessage: `Group: ${groupName}`, | |
| 141 | - })); | |
| 138 | + const decorations: vscode.DecorationOptions[] = matches.map( | |
| 139 | + (range) => ({ | |
| 140 | + range, | |
| 141 | + hoverMessage: `Group: ${groupName}`, | |
| 142 | + }) | |
| 143 | + ); | |
| 142 | 144 | |
| 143 | - editor.setDecorations(style, decorations); | |
| 144 | - } | |
| 145 | + editor.setDecorations(style, decorations); | |
| 146 | + } | |
| 145 | 147 | } |
| 146 | 148 | |
| 147 | 149 | function updateGroupMatches( |
| 148 | - textEditor: vscode.TextEditor, | |
| 149 | - groupMatches: GroupMatchMap, | |
| 150 | - match: RegExpExecArray | |
| 150 | + textEditor: vscode.TextEditor, | |
| 151 | + groupMatches: GroupMatchMap, | |
| 152 | + match: RegExpExecArray | |
| 151 | 153 | ) { |
| 152 | - for (const groupName in match.groups) { | |
| 153 | - const groupMatch = match.groups[groupName]; | |
| 154 | + for (const groupName in match.groups) { | |
| 155 | + const groupMatch = match.groups[groupName]; | |
| 154 | 156 | |
| 155 | - if (groupMatch) { | |
| 156 | - const startInd = match[0].indexOf(groupMatch); | |
| 157 | - const startPos = textEditor.document.positionAt(match.index + startInd); | |
| 158 | - const endInd = startInd + groupMatch.length; | |
| 159 | - const endPos = textEditor.document.positionAt(match.index + endInd); | |
| 160 | - const matchRange = new vscode.Range(startPos, endPos); | |
| 157 | + if (groupMatch) { | |
| 158 | + const startInd = match[0].indexOf(groupMatch); | |
| 159 | + const startPos = textEditor.document.positionAt( | |
| 160 | + match.index + startInd | |
| 161 | + ); | |
| 162 | + const endInd = startInd + groupMatch.length; | |
| 163 | + const endPos = textEditor.document.positionAt(match.index + endInd); | |
| 164 | + const matchRange = new vscode.Range(startPos, endPos); | |
| 161 | 165 | |
| 162 | - if (!groupMatches[groupName]) { | |
| 163 | - // Generate a random color for the group | |
| 164 | - const randomColor = getRandomColor(); | |
| 166 | + if (!groupMatches[groupName]) { | |
| 167 | + // Generate a random color for the group | |
| 168 | + const randomColor = getRandomColor(); | |
| 165 | 169 | |
| 166 | - // Define a new TextEditorDecorationType for the group with the random color | |
| 167 | - groupMatches[groupName] = { | |
| 168 | - style: vscode.window.createTextEditorDecorationType({ | |
| 169 | - backgroundColor: randomColor, | |
| 170 | - color: "black", // You can customize the text color | |
| 171 | - }), | |
| 172 | - matches: [matchRange], | |
| 173 | - }; | |
| 174 | - } else { | |
| 175 | - groupMatches[groupName].matches.push(matchRange); | |
| 176 | - } | |
| 170 | + // Define a new TextEditorDecorationType for the group with the random color | |
| 171 | + groupMatches[groupName] = { | |
| 172 | + style: vscode.window.createTextEditorDecorationType({ | |
| 173 | + backgroundColor: randomColor, | |
| 174 | + color: "black", // You can customize the text color | |
| 175 | + }), | |
| 176 | + matches: [matchRange], | |
| 177 | + }; | |
| 178 | + } else { | |
| 179 | + groupMatches[groupName].matches.push(matchRange); | |
| 180 | + } | |
| 181 | + } | |
| 177 | 182 | } |
| 178 | - } | |
| 179 | 183 | } |
| 180 | 184 | |
| 181 | 185 | function highlightMatches(): void { |
| 182 | - const reEditor = getReEditor(); | |
| 183 | - const textEditor = getTextEditor(); | |
| 184 | - if (!reEditor || !textEditor) { | |
| 185 | - outputChannel.appendLine( | |
| 186 | - "Abort highlighting. Missing reEditor or textEditor." | |
| 187 | - ); | |
| 188 | - return; | |
| 189 | - } | |
| 190 | - let reText = reEditor.document.getText(); | |
| 191 | - if (!reText) { | |
| 192 | - outputChannel.appendLine("Abort highlighting. No text in the regex file."); | |
| 193 | - } | |
| 194 | - let searchText = textEditor.document.getText(); | |
| 195 | - if (searchText === lastText && reText === lastRegex) { | |
| 196 | - return; | |
| 197 | - } | |
| 198 | - lastText = searchText; | |
| 199 | - lastRegex = reText; | |
| 200 | - outputChannel.appendLine("Ready to begin highlighting."); | |
| 186 | + const reEditor = getReEditor(); | |
| 187 | + const textEditor = getTextEditor(); | |
| 188 | + if (!reEditor || !textEditor) { | |
| 189 | + outputChannel.appendLine( | |
| 190 | + "Abort highlighting. Missing reEditor or textEditor." | |
| 191 | + ); | |
| 192 | + return; | |
| 193 | + } | |
| 194 | + let reText = reEditor.document.getText(); | |
| 195 | + if (!reText) { | |
| 196 | + outputChannel.appendLine( | |
| 197 | + "Abort highlighting. No text in the regex file." | |
| 198 | + ); | |
| 199 | + } | |
| 200 | + let searchText = textEditor.document.getText(); | |
| 201 | + if (searchText === lastText && reText === lastRegex) { | |
| 202 | + return; | |
| 203 | + } | |
| 204 | + lastText = searchText; | |
| 205 | + lastRegex = reText; | |
| 206 | + outputChannel.appendLine("Ready to begin highlighting."); | |
| 201 | 207 | |
| 202 | - // Clear all previous text decorations | |
| 203 | - for (const decoration of textDecorations) { | |
| 204 | - textEditor.setDecorations(decoration, []); | |
| 205 | - textDecorations = [baseEditorStyle]; | |
| 206 | - } | |
| 208 | + // Clear all previous text decorations | |
| 209 | + for (const decoration of textDecorations) { | |
| 210 | + textEditor.setDecorations(decoration, []); | |
| 211 | + textDecorations = [baseEditorStyle]; | |
| 212 | + } | |
| 207 | 213 | |
| 208 | - // Perform your matching and highlighting logic here | |
| 209 | - const matches: vscode.Range[] = []; | |
| 210 | - let [flags, hasX] = getRegexFlags(); | |
| 211 | - if (hasX) { | |
| 212 | - reText = reText.replace(/\s/g, ""); | |
| 213 | - } | |
| 214 | - let pattern; | |
| 215 | - try { | |
| 216 | - pattern = new RegExp(reText, flags); | |
| 217 | - } catch { | |
| 218 | - console.log("invalid pattern"); | |
| 219 | - return; | |
| 220 | - } | |
| 221 | - const groupMatches: GroupMatchMap = {}; | |
| 222 | - let match: RegExpExecArray | null; | |
| 223 | - let i = 0; | |
| 224 | - const startTime = new Date().getTime(); | |
| 225 | - while ((match = pattern.exec(searchText))) { | |
| 226 | - if (i > maxMatches) { | |
| 227 | - outputChannel.appendLine(`Max matches of ${maxMatches} reached.`); | |
| 228 | - break; | |
| 214 | + // Perform your matching and highlighting logic here | |
| 215 | + const matches: vscode.Range[] = []; | |
| 216 | + let [flags, hasX] = getRegexFlags(); | |
| 217 | + if (hasX) { | |
| 218 | + reText = reText.replace(/\s/g, ""); | |
| 219 | + } | |
| 220 | + let pattern; | |
| 221 | + try { | |
| 222 | + pattern = new RegExp(reText, flags); | |
| 223 | + } catch { | |
| 224 | + console.log("invalid pattern"); | |
| 225 | + return; | |
| 229 | 226 | } |
| 230 | - if (new Date().getTime() > startTime + 1000) { | |
| 231 | - outputChannel.appendLine(`Timeout of ${timeout} reached.`); | |
| 232 | - break; | |
| 227 | + const groupMatches: GroupMatchMap = {}; | |
| 228 | + let match: RegExpExecArray | null; | |
| 229 | + let i = 0; | |
| 230 | + const startTime = new Date().getTime(); | |
| 231 | + while ((match = pattern.exec(searchText))) { | |
| 232 | + if (i > maxMatches) { | |
| 233 | + console.log(`Max matches of ${maxMatches} reached.`); | |
| 234 | + outputChannel.appendLine(`Max matches of ${maxMatches} reached.`); | |
| 235 | + break; | |
| 236 | + } | |
| 237 | + if (new Date().getTime() > startTime + 1000) { | |
| 238 | + console.log(`Timeout of ${timeout} reached.`); | |
| 239 | + outputChannel.appendLine(`Timeout of ${timeout} reached.`); | |
| 240 | + break; | |
| 241 | + } | |
| 242 | + updateGroupMatches(textEditor, groupMatches, match); | |
| 243 | + const startPos = textEditor.document.positionAt(match.index); | |
| 244 | + const endPos = textEditor.document.positionAt( | |
| 245 | + match.index + match[0].length | |
| 246 | + ); | |
| 247 | + const range = new vscode.Range(startPos, endPos); | |
| 248 | + matches.push(range); | |
| 249 | + i++; | |
| 233 | 250 | } |
| 234 | - updateGroupMatches(textEditor, groupMatches, match); | |
| 235 | - const startPos = textEditor.document.positionAt(match.index); | |
| 236 | - const endPos = textEditor.document.positionAt( | |
| 237 | - match.index + match[0].length | |
| 238 | - ); | |
| 239 | - const range = new vscode.Range(startPos, endPos); | |
| 240 | - matches.push(range); | |
| 241 | - i++; | |
| 242 | - } | |
| 243 | 251 | |
| 244 | - // Apply base decorations | |
| 245 | - textEditor.setDecorations(baseEditorStyle, matches); | |
| 252 | + // Apply base decorations | |
| 253 | + textEditor.setDecorations(baseEditorStyle, matches); | |
| 246 | 254 | |
| 247 | - // Apply decorations to the groups | |
| 248 | - applyGroupMatchDecorations(textEditor, groupMatches); | |
| 255 | + // Apply decorations to the groups | |
| 256 | + applyGroupMatchDecorations(textEditor, groupMatches); | |
| 249 | 257 | } |
| 250 | 258 | |
| 251 | 259 | function toggleFlag(flag: string): void { |
| 252 | - const button = flagButtons[flag].button; | |
| 253 | - const currentState = flagButtons[flag].state; | |
| 254 | - const newState = currentState === "on" ? "off" : "on"; | |
| 260 | + const button = flagButtons[flag].button; | |
| 261 | + const currentState = flagButtons[flag].state; | |
| 262 | + const newState = currentState === "on" ? "off" : "on"; | |
| 255 | 263 | |
| 256 | - flagButtons[flag].state = newState; | |
| 257 | - button.text = `${states[newState]} ${flag.toUpperCase()}`; | |
| 264 | + flagButtons[flag].state = newState; | |
| 265 | + button.text = `${states[newState]} ${flag.toUpperCase()}`; | |
| 258 | 266 | } |
| 259 | 267 | |
| 260 | 268 | export function deactivate() { |
| 261 | - disposeFlagButtons(); | |
| 269 | + disposeFlagButtons(); | |
| 262 | 270 | } |
| 263 | 271 | |
| 264 | 272 | function disposeFlagButtons(): void { |
| 265 | - for (const key in flagButtons) { | |
| 266 | - if (flagButtons.hasOwnProperty(key)) { | |
| 267 | - const innerMapValue = flagButtons[key]; | |
| 268 | - innerMapValue.button.dispose(); | |
| 273 | + for (const key in flagButtons) { | |
| 274 | + if (flagButtons.hasOwnProperty(key)) { | |
| 275 | + const innerMapValue = flagButtons[key]; | |
| 276 | + innerMapValue.button.dispose(); | |
| 277 | + } | |
| 269 | 278 | } |
| 270 | - } | |
| 271 | - // Clear the flagButtons dictionary | |
| 272 | - Object.keys(flagButtons).forEach((key) => delete flagButtons[key]); | |
| 279 | + // Clear the flagButtons dictionary | |
| 280 | + Object.keys(flagButtons).forEach((key) => delete flagButtons[key]); | |
| 273 | 281 | } |