增强的色彩化

Visual Studio Code 的 C/C++ 扩展现在支持语义着色,当 IntelliSense 启用时。增强着色的使用由 C_Cpp.enhancedColorization 设置控制。此设置默认启用。

"C_Cpp.enhancedColorization": "enabled"

主题

颜色可以使用VS Code中现有的主题和颜色自定义支持进行关联。更多信息请参见VS Code主题文档

颜色与语义标记以及TextMate范围相关联。

C/C++ 主题扩展

我们创建了一组与Visual Studio中的默认浅色和深色主题非常相似的VS Code主题,并包含了语义标记的颜色。这些主题可以在这里找到。

IntelliSense 令牌和作用域

Token Semantic Token name Fallback TextMate Scope
Class Template templateType entity.name.type.class.templated
Enumerator enumMember variable.other.enummember
Event (C++/CLI) event variable.other.event
Function function entity.name.function
Function Template templateFunction entity.name.function.templated
Generic Type (C++/CLI) genericType entity.name.type.class.generic
Global Variable variable.global variable.other.global
Label label entity.name.label
Local Variable variable.local variable.other.local
Macro macro entity.name.function.preprocessor
Member Field property variable.other.property
Member Function method entity.name.function.member
Namespace namespace entity.name.namespace
New / Delete newOperator keyword.operator.new
Operator Overload Function operatorOverload entity.name.function.operator
Operator Overload Member memberOperatorOverload entity.name.function.operator.member
Parameter parameter variable.parameter
Property (C++/CLI) cliProperty variable.other.property.cli
Reference Type (C++/CLI) referenceType entity.name.type.class.reference
Static Member Field property.static variable.other.property.static
Static Member Function method.static entity.name.function.member.static
Type type entity.name.type
User-Defined Literal - Number numberLiteral entity.name.operator.custom-literal.number
User-Defined Literal - Raw customLiteral entity.name.operator.custom-literal
User-Defined Literal - String stringLiteral entity.name.operator.custom-literal.string
Value Type (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"
                }
            }
        }
    }