A Regex file extension that makes it way easier to edit large regex.
remove async, update deactivate, and stop using unnamed groups
3 files changed, +25 -33
+4-3src/extension.ts
| @@ -4,7 +4,7 @@ import { editorsContainRegexFile } from "./utils"; | ||
| 4 | 4 | import { regexButtons } from "./regexButtons"; |
| 5 | 5 | import { highlighter } from "./highlighter"; |
| 6 | 6 | |
| 7 | -export async function activate(context: vscode.ExtensionContext) { | |
| 7 | +export function activate(context: vscode.ExtensionContext) { | |
| 8 | 8 | output.activate(); |
| 9 | 9 | regexButtons.activate(context); |
| 10 | 10 | highlighter.activate(context); |
| @@ -29,6 +29,7 @@ export async function activate(context: vscode.ExtensionContext) { | ||
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | export function deactivate() { |
| 32 | - // output.log("Stopping File Regex extension"); | |
| 33 | - output.deactivate(); | |
| 32 | + output.dispose(); | |
| 33 | + highlighter.dispose(); | |
| 34 | + regexButtons.dispose(); | |
| 34 | 35 | } |
+21-8src/highlighter.ts
| @@ -102,13 +102,22 @@ class Highlighter { | ||
| 102 | 102 | }); |
| 103 | 103 | |
| 104 | 104 | for (const groupName in match.groups) { |
| 105 | - const groupIndices = (match as any).indices.groups[groupName]; | |
| 106 | - const start = document.positionAt(groupIndices[0]); | |
| 107 | - const end = document.positionAt(groupIndices[1]); | |
| 108 | - this.updateOrCreateHighlightGroup( | |
| 109 | - groupName, | |
| 110 | - new vscode.Range(start, end) | |
| 111 | - ); | |
| 105 | + const anyMatch = match as any; | |
| 106 | + if ( | |
| 107 | + anyMatch.indices && | |
| 108 | + anyMatch.indices.groups && | |
| 109 | + anyMatch.indices.groups[groupName] | |
| 110 | + ) { | |
| 111 | + const groupIndices = anyMatch.indices.groups[groupName]; | |
| 112 | + const start = document.positionAt(groupIndices[0]); | |
| 113 | + const end = document.positionAt(groupIndices[1]); | |
| 114 | + this.updateOrCreateHighlightGroup( | |
| 115 | + groupName, | |
| 116 | + new vscode.Range(start, end) | |
| 117 | + ); | |
| 118 | + } else { | |
| 119 | + // output.log(groupName); | |
| 120 | + } | |
| 112 | 121 | } |
| 113 | 122 | i++; |
| 114 | 123 | } |
| @@ -116,7 +125,7 @@ class Highlighter { | ||
| 116 | 125 | } |
| 117 | 126 | |
| 118 | 127 | matchRegexGroups(document: vscode.TextDocument) { |
| 119 | - const re = /(?<=\().+?(?=\))/g; | |
| 128 | + const re = /(?<=\()\?<.+?(?=\))/g; | |
| 120 | 129 | const matches = document.getText().matchAll(re); |
| 121 | 130 | let i = 0; |
| 122 | 131 | const maxMatches = getConfig().get("maxMatches") as number; |
| @@ -157,6 +166,10 @@ class Highlighter { | ||
| 157 | 166 | this.highlightMatches(editor); |
| 158 | 167 | } |
| 159 | 168 | } |
| 169 | + | |
| 170 | + dispose() { | |
| 171 | + this.reset(); | |
| 172 | + } | |
| 160 | 173 | } |
| 161 | 174 | |
| 162 | 175 | export const highlighter = new Highlighter(); |
+0-22src/wasm/index.ts
| @@ -1,22 +0,0 @@ | ||
| 1 | -import { output } from "../output"; | |
| 2 | -import * as wasmImport from "./pkg/regex_processor"; | |
| 3 | - | |
| 4 | -class WASM { | |
| 5 | - loaded = false; | |
| 6 | - async default() { | |
| 7 | - wasmImport | |
| 8 | - .default() | |
| 9 | - .then(() => { | |
| 10 | - output.log("WASM loaded"); | |
| 11 | - }) | |
| 12 | - .catch((err) => { | |
| 13 | - output.log(`Error loading WASM: ${err}`); | |
| 14 | - }); | |
| 15 | - } | |
| 16 | - | |
| 17 | - runRegex(pattern: string, text: string) { | |
| 18 | - return wasmImport.find_matches(pattern, text); | |
| 19 | - } | |
| 20 | -} | |
| 21 | - | |
| 22 | -export const wasm = new WASM(); |