A Regex file extension that makes it way easier to edit large regex.
able to apply x flag
4 files changed, +126 -32
+97-17package-lock.json
| @@ -7,6 +7,9 @@ | ||
| 7 | 7 | "": { |
| 8 | 8 | "name": "regex-file", |
| 9 | 9 | "version": "0.0.1", |
| 10 | + "dependencies": { | |
| 11 | + "chalk": "^5.3.0" | |
| 12 | + }, | |
| 10 | 13 | "devDependencies": { |
| 11 | 14 | "@types/glob": "^8.1.0", |
| 12 | 15 | "@types/mocha": "^10.0.1", |
| @@ -955,16 +958,12 @@ | ||
| 955 | 958 | ] |
| 956 | 959 | }, |
| 957 | 960 | "node_modules/chalk": { |
| 958 | - "version": "4.1.2", | |
| 959 | - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", | |
| 960 | - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", | |
| 961 | - "dev": true, | |
| 962 | - "dependencies": { | |
| 963 | - "ansi-styles": "^4.1.0", | |
| 964 | - "supports-color": "^7.1.0" | |
| 965 | - }, | |
| 961 | + "version": "5.3.0", | |
| 962 | + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", | |
| 963 | + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", | |
| 964 | + "license": "MIT", | |
| 966 | 965 | "engines": { |
| 967 | - "node": ">=10" | |
| 966 | + "node": "^12.17.0 || ^14.13 || >=16.0.0" | |
| 968 | 967 | }, |
| 969 | 968 | "funding": { |
| 970 | 969 | "url": "https://github.com/chalk/chalk?sponsor=1" |
| @@ -1312,6 +1311,23 @@ | ||
| 1312 | 1311 | "url": "https://opencollective.com/eslint" |
| 1313 | 1312 | } |
| 1314 | 1313 | }, |
| 1314 | + "node_modules/eslint/node_modules/chalk": { | |
| 1315 | + "version": "4.1.2", | |
| 1316 | + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", | |
| 1317 | + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", | |
| 1318 | + "dev": true, | |
| 1319 | + "license": "MIT", | |
| 1320 | + "dependencies": { | |
| 1321 | + "ansi-styles": "^4.1.0", | |
| 1322 | + "supports-color": "^7.1.0" | |
| 1323 | + }, | |
| 1324 | + "engines": { | |
| 1325 | + "node": ">=10" | |
| 1326 | + }, | |
| 1327 | + "funding": { | |
| 1328 | + "url": "https://github.com/chalk/chalk?sponsor=1" | |
| 1329 | + } | |
| 1330 | + }, | |
| 1315 | 1331 | "node_modules/eslint/node_modules/eslint-scope": { |
| 1316 | 1332 | "version": "7.2.0", |
| 1317 | 1333 | "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.0.tgz", |
| @@ -2116,6 +2132,23 @@ | ||
| 2116 | 2132 | "url": "https://github.com/sponsors/sindresorhus" |
| 2117 | 2133 | } |
| 2118 | 2134 | }, |
| 2135 | + "node_modules/log-symbols/node_modules/chalk": { | |
| 2136 | + "version": "4.1.2", | |
| 2137 | + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", | |
| 2138 | + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", | |
| 2139 | + "dev": true, | |
| 2140 | + "license": "MIT", | |
| 2141 | + "dependencies": { | |
| 2142 | + "ansi-styles": "^4.1.0", | |
| 2143 | + "supports-color": "^7.1.0" | |
| 2144 | + }, | |
| 2145 | + "engines": { | |
| 2146 | + "node": ">=10" | |
| 2147 | + }, | |
| 2148 | + "funding": { | |
| 2149 | + "url": "https://github.com/chalk/chalk?sponsor=1" | |
| 2150 | + } | |
| 2151 | + }, | |
| 2119 | 2152 | "node_modules/lru-cache": { |
| 2120 | 2153 | "version": "6.0.0", |
| 2121 | 2154 | "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", |
| @@ -2944,6 +2977,7 @@ | ||
| 2944 | 2977 | "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", |
| 2945 | 2978 | "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", |
| 2946 | 2979 | "dev": true, |
| 2980 | + "license": "MIT", | |
| 2947 | 2981 | "dependencies": { |
| 2948 | 2982 | "has-flag": "^4.0.0" |
| 2949 | 2983 | }, |
| @@ -3070,6 +3104,23 @@ | ||
| 3070 | 3104 | "webpack": "^5.0.0" |
| 3071 | 3105 | } |
| 3072 | 3106 | }, |
| 3107 | + "node_modules/ts-loader/node_modules/chalk": { | |
| 3108 | + "version": "4.1.2", | |
| 3109 | + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", | |
| 3110 | + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", | |
| 3111 | + "dev": true, | |
| 3112 | + "license": "MIT", | |
| 3113 | + "dependencies": { | |
| 3114 | + "ansi-styles": "^4.1.0", | |
| 3115 | + "supports-color": "^7.1.0" | |
| 3116 | + }, | |
| 3117 | + "engines": { | |
| 3118 | + "node": ">=10" | |
| 3119 | + }, | |
| 3120 | + "funding": { | |
| 3121 | + "url": "https://github.com/chalk/chalk?sponsor=1" | |
| 3122 | + } | |
| 3123 | + }, | |
| 3073 | 3124 | "node_modules/tslib": { |
| 3074 | 3125 | "version": "1.14.1", |
| 3075 | 3126 | "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz", |
| @@ -4114,14 +4165,9 @@ | ||
| 4114 | 4165 | "dev": true |
| 4115 | 4166 | }, |
| 4116 | 4167 | "chalk": { |
| 4117 | - "version": "4.1.2", | |
| 4118 | - "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", | |
| 4119 | - "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", | |
| 4120 | - "dev": true, | |
| 4121 | - "requires": { | |
| 4122 | - "ansi-styles": "^4.1.0", | |
| 4123 | - "supports-color": "^7.1.0" | |
| 4124 | - } | |
| 4168 | + "version": "5.3.0", | |
| 4169 | + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", | |
| 4170 | + "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==" | |
| 4125 | 4171 | }, |
| 4126 | 4172 | "chokidar": { |
| 4127 | 4173 | "version": "3.5.3", |
| @@ -4366,6 +4412,16 @@ | ||
| 4366 | 4412 | "text-table": "^0.2.0" |
| 4367 | 4413 | }, |
| 4368 | 4414 | "dependencies": { |
| 4415 | + "chalk": { | |
| 4416 | + "version": "4.1.2", | |
| 4417 | + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", | |
| 4418 | + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", | |
| 4419 | + "dev": true, | |
| 4420 | + "requires": { | |
| 4421 | + "ansi-styles": "^4.1.0", | |
| 4422 | + "supports-color": "^7.1.0" | |
| 4423 | + } | |
| 4424 | + }, | |
| 4369 | 4425 | "eslint-scope": { |
| 4370 | 4426 | "version": "7.2.0", |
| 4371 | 4427 | "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.0.tgz", |
| @@ -4991,6 +5047,18 @@ | ||
| 4991 | 5047 | "requires": { |
| 4992 | 5048 | "chalk": "^4.1.0", |
| 4993 | 5049 | "is-unicode-supported": "^0.1.0" |
| 5050 | + }, | |
| 5051 | + "dependencies": { | |
| 5052 | + "chalk": { | |
| 5053 | + "version": "4.1.2", | |
| 5054 | + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", | |
| 5055 | + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", | |
| 5056 | + "dev": true, | |
| 5057 | + "requires": { | |
| 5058 | + "ansi-styles": "^4.1.0", | |
| 5059 | + "supports-color": "^7.1.0" | |
| 5060 | + } | |
| 5061 | + } | |
| 4994 | 5062 | } |
| 4995 | 5063 | }, |
| 4996 | 5064 | "lru-cache": { |
| @@ -5683,6 +5751,18 @@ | ||
| 5683 | 5751 | "enhanced-resolve": "^5.0.0", |
| 5684 | 5752 | "micromatch": "^4.0.0", |
| 5685 | 5753 | "semver": "^7.3.4" |
| 5754 | + }, | |
| 5755 | + "dependencies": { | |
| 5756 | + "chalk": { | |
| 5757 | + "version": "4.1.2", | |
| 5758 | + "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz", | |
| 5759 | + "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==", | |
| 5760 | + "dev": true, | |
| 5761 | + "requires": { | |
| 5762 | + "ansi-styles": "^4.1.0", | |
| 5763 | + "supports-color": "^7.1.0" | |
| 5764 | + } | |
| 5765 | + } | |
| 5686 | 5766 | } |
| 5687 | 5767 | }, |
| 5688 | 5768 | "tslib": { |
+7-4package.json
| @@ -84,19 +84,22 @@ | ||
| 84 | 84 | "vsce:package": "vsce package" |
| 85 | 85 | }, |
| 86 | 86 | "devDependencies": { |
| 87 | - "@types/vscode": "^1.79.0", | |
| 88 | 87 | "@types/glob": "^8.1.0", |
| 89 | 88 | "@types/mocha": "^10.0.1", |
| 90 | 89 | "@types/node": "20.2.5", |
| 90 | + "@types/vscode": "^1.79.0", | |
| 91 | 91 | "@typescript-eslint/eslint-plugin": "^5.59.8", |
| 92 | 92 | "@typescript-eslint/parser": "^5.59.8", |
| 93 | + "@vscode/test-electron": "^2.3.2", | |
| 93 | 94 | "eslint": "^8.41.0", |
| 94 | 95 | "glob": "^8.1.0", |
| 95 | 96 | "mocha": "^10.2.0", |
| 96 | - "typescript": "^5.1.3", | |
| 97 | 97 | "ts-loader": "^9.4.3", |
| 98 | + "typescript": "^5.1.3", | |
| 98 | 99 | "webpack": "^5.85.0", |
| 99 | - "webpack-cli": "^5.1.1", | |
| 100 | - "@vscode/test-electron": "^2.3.2" | |
| 100 | + "webpack-cli": "^5.1.1" | |
| 101 | + }, | |
| 102 | + "dependencies": { | |
| 103 | + "chalk": "^5.3.0" | |
| 101 | 104 | } |
| 102 | 105 | } |
+11-10src/highlighter.ts
| @@ -4,6 +4,7 @@ import { getNonRegexEditors, getRegexEditor } from "./utils"; | ||
| 4 | 4 | import { regexButtons } from "./regexButtons"; |
| 5 | 5 | import decorationGenerator from "./decorationGenerator"; |
| 6 | 6 | import { getConfig } from "./global"; |
| 7 | +import chalk from "chalk"; | |
| 7 | 8 | |
| 8 | 9 | type HighlightGroup = { |
| 9 | 10 | ranges: vscode.Range[]; |
| @@ -37,11 +38,15 @@ class Highlighter { | ||
| 37 | 38 | return decoration; |
| 38 | 39 | } |
| 39 | 40 | |
| 40 | - getHighlightGroups( | |
| 41 | - regex: string, | |
| 42 | - flags: string, | |
| 43 | - document: vscode.TextDocument | |
| 44 | - ) { | |
| 41 | + applyXFlag(regex: string) { | |
| 42 | + return regex.replace(/#.*$/gm, "").replace(/\s+/g, ""); | |
| 43 | + } | |
| 44 | + | |
| 45 | + getHighlightGroups(regex: string, document: vscode.TextDocument) { | |
| 46 | + const flags = regexButtons.getFlagString(); | |
| 47 | + if (regexButtons.hasXFlag()) { | |
| 48 | + regex = this.applyXFlag(regex); | |
| 49 | + } | |
| 45 | 50 | const re = new RegExp(regex, flags); |
| 46 | 51 | const matches = document.getText().matchAll(re); |
| 47 | 52 | const highlightGroups: { [key: string]: HighlightGroup } = { |
| @@ -73,11 +78,7 @@ class Highlighter { | ||
| 73 | 78 | // output.log(`Highlighting matches in ${editor.document.fileName}`); |
| 74 | 79 | const regex = regexEditor.document.getText(); |
| 75 | 80 | const flags = regexButtons.getFlagString(); |
| 76 | - const highlightGroups = this.getHighlightGroups( | |
| 77 | - regex, | |
| 78 | - flags, | |
| 79 | - editor.document | |
| 80 | - ); | |
| 81 | + const highlightGroups = this.getHighlightGroups(regex, editor.document); | |
| 81 | 82 | for (const key of Object.keys(highlightGroups)) { |
| 82 | 83 | const group = highlightGroups[key]; |
| 83 | 84 | editor.setDecorations(group.decoration, group.ranges); |
+11-1src/regexButtons.ts
| @@ -70,7 +70,17 @@ class RegexButtons { | ||
| 70 | 70 | return Object.entries(this.flags) |
| 71 | 71 | .filter(([_, flag]) => flag.state === "on") |
| 72 | 72 | .map(([key, _]) => key) |
| 73 | - .join(""); | |
| 73 | + .join("") | |
| 74 | + .replace("x", "") | |
| 75 | + .replace("y", ""); | |
| 76 | + } | |
| 77 | + | |
| 78 | + hasXFlag() { | |
| 79 | + return this.flags.x.state === "on"; | |
| 80 | + } | |
| 81 | + | |
| 82 | + hasYFlag() { | |
| 83 | + return this.flags.y.state === "on"; | |
| 74 | 84 | } |
| 75 | 85 | |
| 76 | 86 | loadConfigFlags() { |