irongit

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

regex-file/src/utils.ts
49 lines1.3 KBJavaScript
1import * as vscode from "vscode";
2import { output } from "./output";
3
4export function editorsContainRegexFile() {
5 const editors = vscode.window.visibleTextEditors;
6 return editors.some(
7 (editor) =>
8 editor.document.languageId === "regex" &&
9 editor.document.uri.scheme === "file"
10 );
11}
12
13export function getRegexEditor() {
14 const editors = vscode.window.visibleTextEditors;
15 return editors.find(
16 (editor) =>
17 editor.document.languageId === "regex" &&
18 editor.document.uri.scheme === "file"
19 );
20}
21
22export function getNonRegexEditors() {
23 const editors = vscode.window.visibleTextEditors;
24 return editors.filter(
25 (editor) =>
26 editor.document.languageId !== "regex" &&
27 editor.document.uri.scheme === "file"
28 );
29}
30
31export 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 const result = originalMethod.apply(this, args);
46 output.log(`Executed ${propertyKey} in ${new Date().getTime() - start}ms`);
47 return result;
48 };
49}