[请参阅下文以了解 v1.45 的更改]
您不仅限于主题提供的语义标记突出显示。您可以通过执行以下操作自己为支持的语言语义标记选择颜色和字体样式:
还可以在用户中定义语义主题规则
设置:
"editor.tokenColorCustomizationsExperimental": {
"property.readonly": {
"foreground": "#35166d"
},
"*.defaultLibrary": {
"fontStyle": "underline"
}
}
来自https://github.com/microsoft/vscode/wiki/Semantic-Highlighting-Overview#as-a-theme-author-do-i-need-to-change-my-theme-to-make-it-work-with-semantic-highlighting
特别是请参阅https://github.com/microsoft/vscode/wiki/Semantic-Highlighting-Overview#how-can-i-find-out-what-semantic-tokens-are-available-and-how-they-are-themed,了解如何发现语义标记。例如:
如果没有列出semantic token type,则该语言服务尚不支持它们。但毫无疑问,当他们这样做时,您会想要修改他们的一些颜色和字体样式选择。
vscode 1.45 会将editor.tokenColorCustomizationsExperimental 重命名为editor.semanticTokenColorCustomizations
见https://github.com/microsoft/vscode/issues/96267
此语法在 2020 年 4 月的 Insiders' Build 中适用于我:
"editor.semanticTokenColorCustomizations": {
"enabled": true,
"rules": {
"enumMember": "#ff0000"
},
"[Default Dark+]": {
"enabled": true,
"rules": {
"variable.readonly": "#ff00ff"
},
}
},
来自https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_45.md#semantic-token-styling-in-the-user-settings:
语义着色可用于 TypeScript 和 JavaScript,具有
对 Java、C++ 的支持正在开发中。默认情况下启用
内置主题并被主题扩展采用。
editor.semanticTokenColorCustomizations 允许用户否决
主题设置和自定义主题。
为所有主题添加语义样式的示例:```
"editor.semanticTokenColorCustomizations": {
"enabled": true,
"rules": {
"property.readonly": {
"foreground": "#35166d"
},
"*.defaultLibrary": {
"bold": true
}
}
}
上面的设置为所有常量着色#35166d 和所有
默认库中出现的符号(例如Math,
setTimeout) 粗体。
为 Dark+ 主题添加语义样式的示例:```
"editor.semanticTokenColorCustomizations": {
"[Default Dark+]": {
"enabled": true,
"rules": {
"parameter": { "underline": true },
"*.declaration": { "bold": true }
}
}
}
The setting above underlines all parameters in the Dark + theme and
makes all symbol declarations bold.
Theming for semantic tokens is explained in more details in the
[Semantic Highlighting
Guide](/api/language-extensions/semantic-highlight-guide#theming).
奇怪的是,在我的测试中,即使在上面的"editor.semanticTokenColorCustomizations" 中使用了enabled: true,您仍然需要启用此设置:
"editor.semanticHighlighting.enabled": true
但这是默认设置。