为了实现您想要的功能,高亮器需要“理解”代码语义。VSCode中的语义高亮于
今年早些时候推出,它对语言的支持仍然有限。C#高亮器背后的引擎OmniSharp开始支持基于Roslyn的语义作为
实验性特性。
您需要首先选择加入以启用该功能,然后重新启动VSCode才能生效。
"csharp.semanticHighlighting.enabled": true,
我假设您知道如何调用作用域检查器,但为了其他读者的方便,它位于
View
>
Command Pallette
>
Developer: Inspect Editor Tokens and Scopes
。
现在您有两个选项来指定自定义突出显示;要么使用新提供的
semantic token
,要么使用老派的
textMateRule
范围。
![semantic](https://istack.dev59.com/ItI3um.webp)
语义标记将为您提供一个修饰符(在此示例中为
static
)。
"editor.semanticTokenColorCustomizations": {
"enabled": true,
"rules": {
"field.static": {
"foreground": "#FF0000",
"fontStyle": "italic",
},
},
},
或者,如果您喜欢使用textMateRules
,我还没有弄清楚如何指定修改器。
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "entity.name.variable.field.cs",
"settings": {
"foreground": "#FF0000",
"fontStyle": "italic",
},
},
]
},
editor.semanticHighlighting.enabled
?(默认情况下应该为 true,但谁知道呢..)另外,请确保 vscode 和 C# 扩展都是最新的。 - NPras