irongit

A Regex file extension that makes it way easier to edit large regex.

able to apply x flag

huncholanehuncholaneauthored
parent ffcec98commit 44341e83beb48d8cc659733d83a9af75e6af04a2Browse files

4 files changed, +126 -32

+97-17package-lock.json
@@ -7,6 +7,9 @@
77 "": {
88 "name": "regex-file",
99 "version": "0.0.1",
10+ "dependencies": {
11+ "chalk": "^5.3.0"
12+ },
1013 "devDependencies": {
1114 "@types/glob": "^8.1.0",
1215 "@types/mocha": "^10.0.1",
@@ -955,16 +958,12 @@
955958 ]
956959 },
957960 "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",
966965 "engines": {
967- "node": ">=10"
966+ "node": "^12.17.0 || ^14.13 || >=16.0.0"
968967 },
969968 "funding": {
970969 "url": "https://github.com/chalk/chalk?sponsor=1"
@@ -1312,6 +1311,23 @@
13121311 "url": "https://opencollective.com/eslint"
13131312 }
13141313 },
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+ },
13151331 "node_modules/eslint/node_modules/eslint-scope": {
13161332 "version": "7.2.0",
13171333 "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.0.tgz",
@@ -2116,6 +2132,23 @@
21162132 "url": "https://github.com/sponsors/sindresorhus"
21172133 }
21182134 },
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+ },
21192152 "node_modules/lru-cache": {
21202153 "version": "6.0.0",
21212154 "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz",
@@ -2944,6 +2977,7 @@
29442977 "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
29452978 "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
29462979 "dev": true,
2980+ "license": "MIT",
29472981 "dependencies": {
29482982 "has-flag": "^4.0.0"
29492983 },
@@ -3070,6 +3104,23 @@
30703104 "webpack": "^5.0.0"
30713105 }
30723106 },
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+ },
30733124 "node_modules/tslib": {
30743125 "version": "1.14.1",
30753126 "resolved": "https://registry.npmjs.org/tslib/-/tslib-1.14.1.tgz",
@@ -4114,14 +4165,9 @@
41144165 "dev": true
41154166 },
41164167 "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=="
41254171 },
41264172 "chokidar": {
41274173 "version": "3.5.3",
@@ -4366,6 +4412,16 @@
43664412 "text-table": "^0.2.0"
43674413 },
43684414 "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+ },
43694425 "eslint-scope": {
43704426 "version": "7.2.0",
43714427 "resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-7.2.0.tgz",
@@ -4991,6 +5047,18 @@
49915047 "requires": {
49925048 "chalk": "^4.1.0",
49935049 "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+ }
49945062 }
49955063 },
49965064 "lru-cache": {
@@ -5683,6 +5751,18 @@
56835751 "enhanced-resolve": "^5.0.0",
56845752 "micromatch": "^4.0.0",
56855753 "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+ }
56865766 }
56875767 },
56885768 "tslib": {
+7-4package.json
@@ -84,19 +84,22 @@
8484 "vsce:package": "vsce package"
8585 },
8686 "devDependencies": {
87- "@types/vscode": "^1.79.0",
8887 "@types/glob": "^8.1.0",
8988 "@types/mocha": "^10.0.1",
9089 "@types/node": "20.2.5",
90+ "@types/vscode": "^1.79.0",
9191 "@typescript-eslint/eslint-plugin": "^5.59.8",
9292 "@typescript-eslint/parser": "^5.59.8",
93+ "@vscode/test-electron": "^2.3.2",
9394 "eslint": "^8.41.0",
9495 "glob": "^8.1.0",
9596 "mocha": "^10.2.0",
96- "typescript": "^5.1.3",
9797 "ts-loader": "^9.4.3",
98+ "typescript": "^5.1.3",
9899 "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"
101104 }
102105 }
+11-10src/highlighter.ts
@@ -4,6 +4,7 @@ import { getNonRegexEditors, getRegexEditor } from "./utils";
44 import { regexButtons } from "./regexButtons";
55 import decorationGenerator from "./decorationGenerator";
66 import { getConfig } from "./global";
7+import chalk from "chalk";
78
89 type HighlightGroup = {
910 ranges: vscode.Range[];
@@ -37,11 +38,15 @@ class Highlighter {
3738 return decoration;
3839 }
3940
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+ }
4550 const re = new RegExp(regex, flags);
4651 const matches = document.getText().matchAll(re);
4752 const highlightGroups: { [key: string]: HighlightGroup } = {
@@ -73,11 +78,7 @@ class Highlighter {
7378 // output.log(`Highlighting matches in ${editor.document.fileName}`);
7479 const regex = regexEditor.document.getText();
7580 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);
8182 for (const key of Object.keys(highlightGroups)) {
8283 const group = highlightGroups[key];
8384 editor.setDecorations(group.decoration, group.ranges);
+11-1src/regexButtons.ts
@@ -70,7 +70,17 @@ class RegexButtons {
7070 return Object.entries(this.flags)
7171 .filter(([_, flag]) => flag.state === "on")
7272 .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";
7484 }
7585
7686 loadConfigFlags() {