How can I get Visual Studio Code to give correct highlighting to a custom type in a CC++ project? - Stack Overflow

I have a C project that has various typedef'd types such as:typedef uint8_t UInt8;typedef struct

I have a C project that has various typedef'd types such as:

typedef uint8_t UInt8;
typedef struct MyStruct_ {
    ...
} MyStruct;

However, unlike built-in types, they don't get correct syntax highlighting:

Note that MyStruct and UInt8 are not colored the same as char and unsigned long.

How can I fix this?

I have a C project that has various typedef'd types such as:

typedef uint8_t UInt8;
typedef struct MyStruct_ {
    ...
} MyStruct;

However, unlike built-in types, they don't get correct syntax highlighting:

Note that MyStruct and UInt8 are not colored the same as char and unsigned long.

How can I fix this?

Share Improve this question edited Feb 3 at 13:29 Bri Bri asked Feb 3 at 4:52 Bri BriBri Bri 2,0823 gold badges24 silver badges65 bronze badges 7
  • 1 char, unsigned and long are keywords. UInt8 and MyStruct are not. – 3CxEZiVlQ Commented Feb 3 at 5:05
  • Interesting question. VS Code is stupidly configurable so I wouldn't be surprised if the capability exists. – user4581301 Commented Feb 3 at 5:05
  • Does uin8_t (Standard-mandated type but not a keyword) get special highlighting? If not you might have to work very hard. – user4581301 Commented Feb 3 at 5:07
  • @user4581301 Yes, types included from stdint.h such as uint8_t do get special highlighting. – Bri Bri Commented Feb 3 at 5:08
  • 1 OT: Don't create type-aliases of existing types, unless it's for creating a semantically significant name. And in both C and C++, all symbols beginning with an underscore followed by an upper-case letter (like _MyStruct) are reserved and should not be defined by your code. – Some programmer dude Commented Feb 3 at 5:51
 |  Show 2 more comments

1 Answer 1

Reset to default 2

Just open your settings.json then add editor.semanticHighlighting.enabled to true and set rules for specific types like I did here for all types. For example you can change color of typedef as well like I did here for type. Find the hex code of the color you want may be by using any color picker tool.

{
    "editor.semanticHighlighting.enabled": true,
    "editor.semanticTokenColorCustomizations": 
    {
        "rules": 
        {
            "type":
            {
                "foreground": "#6c9ada"
            }
        }
    }
}

Note: I didn't look for the exact color just close enough.

Here MyStruct type now in that #6c9ada color close to that default char type.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745248978a4618559.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信