如何在VS Code中更改C/C++数据成员引用的颜色?

bt1cpqcv  于 8个月前  发布在  C/C++
关注(0)|答案(1)|浏览(124)

我试图改变C中结构中变量的颜色。特别是(*stack_a)->sorted_pos成员(请参阅附图)。我想把这些变量的粉红色变成橙子。
(picture example of struct variable to be changed)
再举一个简单的例子:

typedef struct { int bar; } Foo;
int baz(Foo* foo) {
   return foo->bar; // <- I want to change `bar` here
}

我已经为我的主题(Spaceduck)浏览了.json文件,并试图改变其中的许多变量以找到正确的变量,但没有成功。我还尝试在谷歌上搜索该特定变量的名称(我猜它可能是keyword.struct.variable或类似的东西),但找不到它。
我在哪里可以找到这些信息,或者什么是变量的文本称为?

zed5wv10

zed5wv101#

您可以在命令面板中使用Developer: Inspect Editor Tokens and Scopes来获取有关颜色范围的信息。
如果没有任何C语言支持扩展,那么您将使用variable.other.member.cvariable.other.property.cpp TextMate作用域。例如:(将其放入settings.json中)

"editor.tokenColorCustomizations": {
    "[name of your selected theme goes here]": { // optionally remove this wrapper to apply to all themes
        "textMateRules": [
            {
                "scope": "variable.other.member.c",
                "settings": {
                    "foreground": "#FF0000", // TODO
                },
            },
        ].
    },
},

使用Microsoft C/C扩展,您需要使用variable.other.property.cvariable.other.property.c TextMate作用域,这(不幸的是?)适用于成员变量引用及其声明。或者您可以使用"scope": "variable.other.member.c, variable.other.property.c, variable.other.property.cpp",来处理这两种情况。Microsoft C/C扩展也提供了semantic highlighting,因此您也可以在settings.json中编写类似的内容以获得类似的效果:

"editor.semanticTokenColorCustomizations": {
    "[name of your selected theme goes here]": { // optionally remove this wrapper to apply to all themes
        "rules": {
            "property:c": {
                "foreground": "#FF0000", // TODO
            },
            "property:cpp": {
                "foreground": "#FF0000", // TODO
            },
        },
    },
},

相关问题