A Regex file extension that makes it way easier to edit large regex.
created timeit decorator
4 files changed, +73 -17
+3-1src/highlighter.ts
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import * as vscode from "vscode"; |
| 2 | 2 | import { output } from "./output"; |
| 3 | -import { getNonRegexEditors, getRegexEditor } from "./utils"; | |
| 3 | +import { getNonRegexEditors, getRegexEditor, timeit } from "./utils"; | |
| 4 | 4 | import { regexButtons } from "./regexButtons"; |
| 5 | 5 | import decorationGenerator from "./decorationGenerator"; |
| 6 | 6 | import { getConfig } from "./global"; |
| @@ -28,6 +28,7 @@ class Highlighter { | ||
| 28 | 28 | ); |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | + @timeit | |
| 31 | 32 | reset() { |
| 32 | 33 | output.clear(); |
| 33 | 34 | this.getDecorationTypes().forEach((decoration) => { |
| @@ -143,6 +144,7 @@ class Highlighter { | ||
| 143 | 144 | } |
| 144 | 145 | } |
| 145 | 146 | |
| 147 | + @timeit | |
| 146 | 148 | highlightMatches(editor: vscode.TextEditor) { |
| 147 | 149 | for (const key of Object.keys(this.highlightGroups)) { |
| 148 | 150 | const group = this.highlightGroups[key]; |
+35-2src/output.ts
| @@ -1,5 +1,8 @@ | ||
| 1 | +import chalk from "chalk"; | |
| 1 | 2 | import * as vscode from "vscode"; |
| 2 | 3 | |
| 4 | +type Level = "info" | "error" | "warning"; | |
| 5 | + | |
| 3 | 6 | class Output { |
| 4 | 7 | outputChannel: vscode.OutputChannel | undefined; |
| 5 | 8 | |
| @@ -26,9 +29,39 @@ class Output { | ||
| 26 | 29 | this.outputChannel?.hide(); |
| 27 | 30 | } |
| 28 | 31 | |
| 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 | |
| 30 | 64 | this.outputChannel?.appendLine(message); |
| 31 | - console.log(message); | |
| 32 | 65 | } |
| 33 | 66 | |
| 34 | 67 | deactivate() { |
+22-0src/utils.ts
| @@ -1,4 +1,5 @@ | ||
| 1 | 1 | import * as vscode from "vscode"; |
| 2 | +import { output } from "./output"; | |
| 2 | 3 | |
| 3 | 4 | export function editorsContainRegexFile() { |
| 4 | 5 | const editors = vscode.window.visibleTextEditors; |
| @@ -26,3 +27,24 @@ export function getNonRegexEditors() { | ||
| 26 | 27 | editor.document.uri.scheme === "file" |
| 27 | 28 | ); |
| 28 | 29 | } |
| 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 @@ | ||
| 1 | 1 | { |
| 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 | + } | |
| 16 | 15 | } |