irongit

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

created timeit decorator

huncholanehuncholaneauthored
parent 98adb26commit 298ba722287be9159b0b2d33a508bb113a65e7cbBrowse files

4 files changed, +73 -17

+3-1src/highlighter.ts
@@ -1,6 +1,6 @@
11 import * as vscode from "vscode";
22 import { output } from "./output";
3-import { getNonRegexEditors, getRegexEditor } from "./utils";
3+import { getNonRegexEditors, getRegexEditor, timeit } from "./utils";
44 import { regexButtons } from "./regexButtons";
55 import decorationGenerator from "./decorationGenerator";
66 import { getConfig } from "./global";
@@ -28,6 +28,7 @@ class Highlighter {
2828 );
2929 }
3030
31+ @timeit
3132 reset() {
3233 output.clear();
3334 this.getDecorationTypes().forEach((decoration) => {
@@ -143,6 +144,7 @@ class Highlighter {
143144 }
144145 }
145146
147+ @timeit
146148 highlightMatches(editor: vscode.TextEditor) {
147149 for (const key of Object.keys(this.highlightGroups)) {
148150 const group = this.highlightGroups[key];
+35-2src/output.ts
@@ -1,5 +1,8 @@
1+import chalk from "chalk";
12 import * as vscode from "vscode";
23
4+type Level = "info" | "error" | "warning";
5+
36 class Output {
47 outputChannel: vscode.OutputChannel | undefined;
58
@@ -26,9 +29,39 @@ class Output {
2629 this.outputChannel?.hide();
2730 }
2831
29- log(message: string) {
32+ log(message: string, level: Level = "info") {
33+ const dateString = new Date().toLocaleTimeString();
34+ const reset = "\x1b[0m";
35+ const blue = "\x1b[34m";
36+ const green = "\x1b[32m";
37+ const red = "\x1b[31m";
38+ const yellow = "\x1b[33m";
39+ const whiteBright = "\x1b[97m";
40+
41+ let output = `[${dateString}] `;
42+ if (level === "info") {
43+ output += `[info] `;
44+ } else if (level === "error") {
45+ output += `[error] `;
46+ } else if (level === "warning") {
47+ output += `[warning] `;
48+ }
49+ output += `${message}`;
50+
51+ // Log to console with colors
52+ let coloredOutput = `${blue}[${dateString}] ${reset}`;
53+ if (level === "info") {
54+ coloredOutput += `${green}[info] ${reset}`;
55+ } else if (level === "error") {
56+ coloredOutput += `${red}[error] ${reset}`;
57+ } else if (level === "warning") {
58+ coloredOutput += `${yellow}[warning] ${reset}`;
59+ }
60+ coloredOutput += `${whiteBright}${message}${reset}`;
61+ console.log(coloredOutput);
62+
63+ // Log to VS Code output channel without colors
3064 this.outputChannel?.appendLine(message);
31- console.log(message);
3265 }
3366
3467 deactivate() {
+22-0src/utils.ts
@@ -1,4 +1,5 @@
11 import * as vscode from "vscode";
2+import { output } from "./output";
23
34 export function editorsContainRegexFile() {
45 const editors = vscode.window.visibleTextEditors;
@@ -26,3 +27,24 @@ export function getNonRegexEditors() {
2627 editor.document.uri.scheme === "file"
2728 );
2829 }
30+
31+export function timeit(
32+ target: any,
33+ propertyKey: string,
34+ descriptor?: PropertyDescriptor
35+) {
36+ if (!descriptor) {
37+ console.error(
38+ "Descriptor is undefined. @timeit should be used on methods."
39+ );
40+ return;
41+ }
42+ const originalMethod = descriptor.value;
43+ descriptor.value = function (...args: any[]) {
44+ const start = new Date().getTime();
45+ output.log("Starting " + propertyKey);
46+ const result = originalMethod.apply(this, args);
47+ output.log(`Executed ${propertyKey} in ${new Date().getTime() - start}ms`);
48+ return result;
49+ };
50+}
+13-14tsconfig.json
@@ -1,16 +1,15 @@
11 {
2- "compilerOptions": {
3- "module": "commonjs",
4- "target": "ES2020",
5- "lib": [
6- "ES2020"
7- ],
8- "sourceMap": true,
9- "rootDir": "src",
10- "strict": true /* enable all strict type-checking options */
11- /* Additional Checks */
12- // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
13- // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
14- // "noUnusedParameters": true, /* Report errors on unused parameters. */
15- }
2+ "compilerOptions": {
3+ "module": "commonjs",
4+ "target": "ES2020",
5+ "experimentalDecorators": true,
6+ "lib": ["ES2020"],
7+ "sourceMap": true,
8+ "rootDir": "src",
9+ "strict": true /* enable all strict type-checking options */
10+ /* Additional Checks */
11+ // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
12+ // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
13+ // "noUnusedParameters": true, /* Report errors on unused parameters. */
14+ }
1615 }