Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Visual Studio Code to give correct highlighting to a custom type in a C / C++ project?

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:

Screenshot of incorrect syntax highlighting

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

How can I fix this?

like image 794
Bri Bri Avatar asked Oct 17 '25 13:10

Bri Bri


1 Answers

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.

screenshoot

like image 179
DozingDuckling Avatar answered Oct 19 '25 04:10

DozingDuckling