Is there a way to give distinct colors to classes, enums, and interfaces in VS Code for better differentiation? They all look the same, even the color of the variables look the same as the class name color.
You can use TextMate token scopes, but check also if the language support extension you’re using supports semantic highlighting. If it does, then you can use the standard token types. Ex. in your settings.json file:
"editor.semanticTokenColorCustomizations": {
"[your theme name here]": { // remove this theme wrapper to apply for all themes
"rules": {
"class": "#ff0000", // TODO
"interface": "#ff0000", // TODO
"enum": "#ff0000", // TODO
},
},
},
If not, then you need to figure out what TextMate token scopes are defined by your language support extension(s) for the tokens you want to colour, which you can do with the scope inspector tool. Use the Developer: Inspect Editor Tokens and Scopes command in the command palette to open the scope inspector widget and move the cursor over each of the tokens you are interested in, and then look at what tokens are defined for them. Ex. for TypeScript:
"editor.tokenColorCustomizations": {
"[your theme name here]": { // remove this theme wrapper to apply for all themes
"textMateRules": [
{
"scope": "entity.name.type.enum",
"settings": {
"foreground": "#ff0000", // TODO
},
},
{
"scope": "entity.name.type.class",
"settings": {
"foreground": "#ff0000", // TODO
},
},
{
"scope": "entity.name.type.interface",
"settings": {
"foreground": "#ff0000", // TODO
},
},
],
},
},
2
Answers
To achieve this, follow these steps:
Next, add the following code:
This configuration modifies the color of interfaces, enums, and classes using the provided color codes. you can change the color codes how you want.
You can use TextMate token scopes, but check also if the language support extension you’re using supports semantic highlighting. If it does, then you can use the standard token types. Ex. in your settings.json file:
If not, then you need to figure out what TextMate token scopes are defined by your language support extension(s) for the tokens you want to colour, which you can do with the scope inspector tool. Use the
Developer: Inspect Editor Tokens and Scopes
command in the command palette to open the scope inspector widget and move the cursor over each of the tokens you are interested in, and then look at what tokens are defined for them. Ex. for TypeScript: