为了实现你想要的,荧光笔需要“理解”代码语义。 VSCode 中引入了语义突出显示今年年初 https://github.com/microsoft/vscode/wiki/Semantic-Highlighting-Overview,而且它对语言的支持仍然有限。 OmniSharp 是 C# 荧光笔背后的引擎,开始支持基于 Roslyn 的语义作为实验性特征 https://github.com/OmniSharp/omnisharp-vscode/pull/3667.
您首先需要选择启用该功能,然后重新启动 VSCode 才能使其生效。
"csharp.semanticHighlighting.enabled": true,
我假设您知道如何调用范围检查器,但为了其他读者,它位于View
> Command Pallette
> Developer: Inspect Editor Tokens and Scopes
您现在有两个选项来指定自定义突出显示;要么使用新可用的semantic token
,或者老派的textMateRule
scopes.
语义标记也会给你一个修饰符(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",
},
},
]
},