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

问题描述 投票:0回答:1

我正在尝试更改 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 文件,并尝试更改其中的许多变量以找到正确的变量,但没有成功。我还尝试用谷歌搜索来查找该特定变量的名称(我猜它会是类似 keywords.struct.variable 或类似的东西),但找不到它。

有谁知道我可以在哪里找到这些信息,或者文本的变量叫什么?

c++ c visual-studio-code syntax-highlighting
1个回答
0
投票

您可以使用

命令调色板
中的Developer: Inspect Editor Tokens and Scopes来获取有关颜色范围的信息。

如果没有任何 C 语言支持扩展,那么您将使用

variable.other.member.c
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.c
TextMate 作用域,这(不幸的是?)适用于成员变量引用及其声明。或者您可以使用
"scope": "variable.other.member.c, variable.other.property.c",
来处理这两种情况。 Microsoft C/C++ 扩展还提供了语义突出显示,因此您也可以在 settings.json 中编写类似的内容以获得类似的效果:

"editor.semanticTokenColorCustomizations": {
   
        "rules": {
            "property:c": {
                "foreground": "#FF0000", // TODO
            },
        },
    },
},
© www.soinside.com 2019 - 2024. All rights reserved.