在 C/C++ 中,在 Eclipse 编辑器中,您可以在更多语言级别设置颜色:
例如函数参数,局部变量可以有不同的颜色。
可以更改静态和全局变量颜色。可以配置宏和宏引用。
如何在 Visual Studio Code 中做到这一点?我不确定 text mate tmLanguage 是否可以实现这一点。我找不到任何文档。
最佳答案
[有关 v1.45 更改的更多信息,请参见下文]
您不仅限于主题提供的语义标记突出显示。您可以通过执行以下操作为支持的语言语义标记自己选择颜色和字体样式:
It's also possible to define semantic theming rules in the user settings:
"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
此语法在 Insiders' Build 2020 年 4 月对我有用:
"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 :
Semantic coloring is available for TypeScript and JavaScript, with support for Java, C++ in the works. It is enabled by default for built-in themes and being adopted by theme extensions.
The
editor.semanticTokenColorCustomizations
allows users to overrule the theme settings and to customize the theming.Example that adds semantic styling to all themes: ```
"editor.semanticTokenColorCustomizations": { "enabled": true, "rules": { "property.readonly": { "foreground": "#35166d" }, "*.defaultLibrary": { "bold": true } } }
The setting above colors all constants with
#35166d
and all occurrences of symbols from a default library (e.g.Math
,setTimeout
) bold.
Example that adds semantic styling to the Dark+ themes: ```
"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).
奇怪的是,在我的测试中,即使使用
enabled: true
在上面"editor.semanticTokenColorCustomizations"
您仍然需要启用此设置: "editor.semanticHighlighting.enabled": true
但这是默认设置。
关于eclipse - VS Code : How to set semantic syntax coloring like Eclipse does. 默认语法着色不这样做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50994340/