Skip to content

Commit 5c16754

Browse files
committed
Fix end pattern backreferencing
1 parent 3c8fb34 commit 5c16754

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/DiagnosticCollection.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ function diagnosticsOnigurumaRegexErrors(diagnostics: vscode.Diagnostic[], trees
272272
* VSCode TextMate escapes all special regex characters
273273
* and replaces the backreferences directly
274274
*/
275-
if (/\\[1-9](\d{2})?(?!\d)/.test(regex)) {
275+
if (/\\[0-9]/.test(regex)) {
276276
const beginNode = getLastNode(regexNode.parent!.parent!, 'begin')?.childForFieldName('regex');
277277
if (beginNode) {
278278
const beginRegex = trees.regexTrees.get(beginNode.id)?.rootNode;
@@ -296,11 +296,12 @@ function diagnosticsOnigurumaRegexErrors(diagnostics: vscode.Diagnostic[], trees
296296
// https://github.com/microsoft/vscode-textmate/blob/main/src/utils.ts#L160
297297
// https://github.com/microsoft/vscode-textmate/issues/239
298298
regex = regex.replace(
299-
new RegExp(`\\\\${index}(?!\\d)`, 'g'),
299+
new RegExp(`\\\\0*${index}(?![0-9])`, 'g'), // TextMate 2.0 only targets single digit backreferences `\\[0-9]` vs `\\[0-9]+`
300300
groupText,
301301
);
302302
index++;
303303
}
304+
regex = regex.replace(new RegExp(`\\\\[0-9]+`, 'g'), ''); // All non-existent backreferences are removed
304305
}
305306
}
306307
}

0 commit comments

Comments
 (0)