Skip to content

Commit 390a529

Browse files
committed
Fix microsoft#40279 - rewrite php grammar rule to avoid regex that hangs vscode-textmate
1 parent d14586e commit 390a529

2 files changed

Lines changed: 17 additions & 2 deletions

File tree

extensions/php/build/update-grammar.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ function adaptInjectionScope(grammar) {
2020
injections[newInjectionKey] = injection;
2121
}
2222

23-
updateGrammar.update('atom/language-php', 'grammars/php.cson', './syntaxes/php.tmLanguage.json', undefined);
23+
// Workaround for https://github.com/Microsoft/vscode/issues/40279
24+
// and https://github.com/Microsoft/vscode-textmate/issues/59
25+
function fixBadRegex(grammar) {
26+
const scopeResolution = grammar.repository['scope-resolution'];
27+
if (scopeResolution) {
28+
const match = scopeResolution.patterns[0].match;
29+
if (match === '(?i)([a-z_\\x{7f}-\\x{7fffffff}\\\\][a-z0-9_\\x{7f}-\\x{7fffffff}\\\\]*)(?=\\s*::)') {
30+
scopeResolution.patterns[0].match = '([A-Za-z_\\x{7f}-\\x{7fffffff}\\\\][A_Za-z0-9_\\x{7f}-\\x{7fffffff}\\\\]*)(?=\\s*::)';
31+
return;
32+
}
33+
}
34+
35+
throw new Error(`fixBadRegex callback couldn't patch the regex. It may be obsolete`);
36+
}
37+
38+
updateGrammar.update('atom/language-php', 'grammars/php.cson', './syntaxes/php.tmLanguage.json', fixBadRegex);
2439
updateGrammar.update('atom/language-php', 'grammars/html.cson', './syntaxes/html.tmLanguage.json', adaptInjectionScope);
2540

extensions/php/syntaxes/php.tmLanguage.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2430,7 +2430,7 @@
24302430
"scope-resolution": {
24312431
"patterns": [
24322432
{
2433-
"match": "(?i)([a-z_\\x{7f}-\\x{7fffffff}\\\\][a-z0-9_\\x{7f}-\\x{7fffffff}\\\\]*)(?=\\s*::)",
2433+
"match": "([A-Za-z_\\x{7f}-\\x{7fffffff}\\\\][A_Za-z0-9_\\x{7f}-\\x{7fffffff}\\\\]*)(?=\\s*::)",
24342434
"captures": {
24352435
"1": {
24362436
"patterns": [

0 commit comments

Comments
 (0)