Patch razor grammar to use html derivative (#257827)

Fixes #254686
This commit is contained in:
Alex Ross
2025-07-25 15:10:08 +02:00
committed by GitHub
parent 4e2076ab29
commit 9ef59e22ed
2 changed files with 30 additions and 4 deletions

View File

@@ -8,6 +8,32 @@ import * as vscodeGrammarUpdater from 'vscode-grammar-updater';
function patchGrammar(grammar) {
grammar.scopeName = 'text.html.cshtml';
let patchCount = 0;
let visit = function (rule, parent) {
if (rule.include?.startsWith('text.html.basic')) {
patchCount++;
rule.include = 'text.html.derivative';
}
for (let property in rule) {
let value = rule[property ];
if (typeof value === 'object') {
visit(value, { node: rule, property: property, parent: parent });
}
}
};
let roots = [grammar.repository, grammar.patterns];
for (let root of roots) {
for (let key in root) {
visit(root[key], { node: root, property: key, parent: undefined });
}
}
if (patchCount !== 4) {
console.warn(`Expected to patch 4 occurrences of text.html.basic: Was ${patchCount}`);
}
return grammar;
}

View File

@@ -34,7 +34,7 @@
"include": "#razor-control-structures"
},
{
"include": "text.html.basic"
"include": "text.html.derivative"
}
],
"repository": {
@@ -155,7 +155,7 @@
"include": "#razor-control-structures"
},
{
"include": "text.html.basic"
"include": "text.html.derivative"
}
]
}
@@ -239,7 +239,7 @@
},
"patterns": [
{
"include": "text.html.basic#attribute"
"include": "text.html.derivative"
}
],
"end": "/?>",
@@ -286,7 +286,7 @@
"include": "#razor-control-structures"
},
{
"include": "text.html.basic#attribute"
"include": "text.html.derivative"
}
]
},