Is there a way to extend the default csharp.tmLanguage
with some additional rule? With references to existing scopes?
You can include a grammar just like:
{ "include": "source.cs" }
But if you replace the grammar with your own (defining your own source.cs
scope), then you cannot include the original source.cs
scope anymore into it (VS Code reports it failed tokenize the file).
Visual Studio Code supports grammar injection, like:
"grammars": [
{
"scopeName": "source.todo",
"path": "./syntaxes/todo.json",
"injectTo": [ "source.js", "source.ts" ]
},
Which is surprisingly under documented. It works, but you can inject into existing scopes, except the top level source
scope. Also, it seems to me you can inject additions only, instead override rules. So again, I cannot extend grammar this way.
For now I go with a workaround, where I contribute 2 grammars. One is the original C# grammar with a fake name, the 2nd is the overwriting C# grammar, including all the original rules via the fake scope. I wish there was a way without this.
This way I can add some rules "before" I include the original grammar. But still, these are additions, I cannot really extend existing rules.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With