Skip to content

Commit 02d6bc0

Browse files
committed
Add onigurumaToES diagonstics
1 parent 8d6d492 commit 02d6bc0

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

src/DiagnosticCollection.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as webTreeSitter from 'web-tree-sitter';
33
import * as vscodeOniguruma from 'vscode-oniguruma';
44
import * as textmateOnigmo from "./Onigmo/Onigmo";
55
import * as PCRE from '@syntropiq/libpcre-ts';
6+
import * as onigurumaToES from 'oniguruma-to-es';
67
import { closeEnoughQuestionMark, DocumentSelector, getPackageJSON, stringify, wagnerFischer } from "./extension";
78
import { getLastNode, getTrees, queryNode, toRange, trees } from "./TreeSitter";
89
import { ignoreDiagnosticsUnusedRepos } from "./Providers/CodeActionsProvider";
@@ -563,6 +564,28 @@ async function diagnosticsOnigurumaRegexErrors(diagnostics: vscode.Diagnostic[],
563564
);
564565

565566

567+
let errorCodeES: string | undefined;
568+
try {
569+
// https://shiki.style/ uses https://github.com/slevithan/oniguruma-to-es
570+
// There is no escaping backreferences, but aimless backreferences are ignored
571+
572+
573+
const options: onigurumaToES.ToRegExpOptions = {
574+
accuracy: 'default',
575+
verbose: true,
576+
rules: {
577+
// Follow `vscode-oniguruma` which enables this Oniguruma option by default
578+
captureGroup: true,
579+
allowOrphanBackrefs: hasBackreferences,
580+
581+
},
582+
};
583+
const jsRegex = onigurumaToES.toRegExpDetails(regex, options);
584+
} catch (error: any) {
585+
errorCodeES = error.toString();
586+
}
587+
588+
566589
// const string = vscodeOniguruma.createOnigString(''); // blank. Maybe can test against a user provided string?
567590
// const match = scanner.findNextMatchSync(string, 0); // returns null if `regex` is invalid
568591
// vscode.window.showInformationMessage(`Oniguruma ${(performance.now() - start).toFixed(3)}ms\n${JSON.stringify(match, stringify)}`);
@@ -585,6 +608,16 @@ async function diagnosticsOnigurumaRegexErrors(diagnostics: vscode.Diagnostic[],
585608
source: 'PCRE',
586609
});
587610
}
611+
612+
if (errorCodeES) {
613+
diagnostics.push({
614+
range: range,
615+
message: errorCodeES,
616+
severity: vscode.DiagnosticSeverity.Warning,
617+
source: 'Shiki',
618+
});
619+
}
620+
588621
continue;
589622
}
590623

@@ -614,6 +647,15 @@ async function diagnosticsOnigurumaRegexErrors(diagnostics: vscode.Diagnostic[],
614647
source: 'PCRE',
615648
});
616649
}
650+
651+
if (errorCodeES) {
652+
diagnostics.push({
653+
range: range,
654+
message: `Regex incompatible with Shiki (oniguruma-to-es)\n${errorCodeES}`,
655+
severity: vscode.DiagnosticSeverity.Warning,
656+
source: 'Shiki',
657+
});
658+
}
617659
}
618660
// vscode.window.showInformationMessage(`Oniguruma ${(performance.now() - start).toFixed(3)}ms`);
619661
}

0 commit comments

Comments
 (0)