irongit

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

remove async, update deactivate, and stop using unnamed groups

huncholanehuncholaneauthored
parent 69c6109commit 061f71debd966d723f9e0461d33f4564985e9924Browse files

3 files changed, +25 -33

+4-3src/extension.ts
@@ -4,7 +4,7 @@ import { editorsContainRegexFile } from "./utils";
44 import { regexButtons } from "./regexButtons";
55 import { highlighter } from "./highlighter";
66
7-export async function activate(context: vscode.ExtensionContext) {
7+export function activate(context: vscode.ExtensionContext) {
88 output.activate();
99 regexButtons.activate(context);
1010 highlighter.activate(context);
@@ -29,6 +29,7 @@ export async function activate(context: vscode.ExtensionContext) {
2929 }
3030
3131 export function deactivate() {
32- // output.log("Stopping File Regex extension");
33- output.deactivate();
32+ output.dispose();
33+ highlighter.dispose();
34+ regexButtons.dispose();
3435 }
+21-8src/highlighter.ts
@@ -102,13 +102,22 @@ class Highlighter {
102102 });
103103
104104 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+ }
112121 }
113122 i++;
114123 }
@@ -116,7 +125,7 @@ class Highlighter {
116125 }
117126
118127 matchRegexGroups(document: vscode.TextDocument) {
119- const re = /(?<=\().+?(?=\))/g;
128+ const re = /(?<=\()\?<.+?(?=\))/g;
120129 const matches = document.getText().matchAll(re);
121130 let i = 0;
122131 const maxMatches = getConfig().get("maxMatches") as number;
@@ -157,6 +166,10 @@ class Highlighter {
157166 this.highlightMatches(editor);
158167 }
159168 }
169+
170+ dispose() {
171+ this.reset();
172+ }
160173 }
161174
162175 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();