增强的着色
当 IntelliSense 启用时,Visual Studio Code C/C++ 扩展现在支持语义着色。增强的着色功能由 C_Cpp.enhancedColorization 设置控制。此设置默认启用。
"C_Cpp.enhancedColorization": "enabled"
主题
可以通过 VS Code 中现有的主题和颜色自定义支持来关联颜色。有关更多信息,请参阅 VS Code 主题文档。
颜色与 语义令牌 以及 TextMate 作用域 相关联。
C/C++ 主题扩展
我们创建了一组 VS Code 主题,它们与 Visual Studio 的默认浅色和深色主题非常相似,并包含语义令牌的颜色。这些主题可以在此处找到。
IntelliSense 令牌和作用域
标记 | 语义令牌名称 | 回退 TextMate 作用域 |
---|---|---|
类模板 | templateType | entity.name.type.class.templated |
枚举器 | enumMember | variable.other.enummember |
事件 (C++/CLI) | event | variable.other.event |
函数 | function | entity.name.function |
函数模板 | templateFunction | entity.name.function.templated |
泛型类型 (C++/CLI) | genericType | entity.name.type.class.generic |
全局变量 | variable.global | variable.other.global |
标签 | label | entity.name.label |
局部变量 | variable.local | variable.other.local |
宏 | macro | entity.name.function.preprocessor |
成员字段 | property | variable.other.property |
成员函数 | method | entity.name.function.member |
命名空间 | namespace | entity.name.namespace |
New / Delete | newOperator | keyword.operator.new |
运算符重载函数 | operatorOverload | entity.name.function.operator |
成员运算符重载 | memberOperatorOverload | entity.name.function.operator.member |
参数 | 参数 | variable.parameter |
属性 (C++/CLI) | cliProperty | variable.other.property.cli |
引用类型 (C++/CLI) | referenceType | entity.name.type.class.reference |
静态成员字段 | property.static | variable.other.property.static |
静态成员函数 | method.static | entity.name.function.member.static |
类型 | 类型 | entity.name.type |
用户定义字面量 - 数字 | numberLiteral | entity.name.operator.custom-literal.number |
用户定义字面量 - 原始 | customLiteral | entity.name.operator.custom-literal |
用户定义字面量 - 字符串 | stringLiteral | entity.name.operator.custom-literal.string |
值类型 (C++/CLI) | valueType | entity.name.type.class.value |
在设置中自定义颜色
颜色也可以在设置中进行全局覆盖
"editor.semanticTokenColorCustomizations": {
"rules": {
"templateType": {
"foreground": "#ff0000",
"fontStyle": "italic bold underline"
}
}
}
或者,按每个主题进行覆盖
"editor.semanticTokenColorCustomizations": {
"[Visual Studio Dark]": {
"rules": {
"templateType": {
"foreground": "#ff0000",
"fontStyle": "italic bold underline"
}
}
}
}