skip to Main Content

I’m using Visual Studio Code with the Gruvbox theme. I have the following configuration in my settings.json:

"editor.tokenColorCustomizations": {
        "[Gruvbox Dark Medium]": {
            "textMateRules": [
                {
                    "scope": "source.c, entity.name.function.preprocessor",
                    "settings": {
                        "foreground": "#eb9b82"
                    }
                }
            ]
        }
    },

This colors C macros differently than the default. This works as expected, except that if I open a Rust file, Rust macros are also colored differently, despite the source.c in the scope field. How can I have this settings apply only to C files? Rust macros have the exclamation mark at the end which differentiate them from regular function, I don’t a different color for them.

EDIT:
Here is what the VSCode token inspector shows without the above settings for the println! macro:

1

Here is what the VSCode token inspector shows with the above settings enabled:

2

2

Answers


  1. As Mark noticed, you have a comma between your two things. You wanted a descendent selector, but you turned it into grouping. See https://macromates.com/manual/en/scope_selectors. Remove the comma.

    You could just use semantic highlighting customization instead?

    "editor.semanticTokenColorCustomizations": {
        "[Your Theme Name Here]": { // TODO put your theme name here, or remove this wrapper to apply regardless of current theme
            "rules": {
                "macro.defaultLibrary:rust": {
                    "foreground": "#FF0000", // TODO
                    // "fontStyle": "bold",
                },
            },
        },
    },
    
    Login or Signup to reply.
  2. You were close with your original attempt. Try this instead:

    "editor.tokenColorCustomizations": {
            "[Gruvbox Dark Medium]": {
                "textMateRules": [
                    {
                        // remove the comma
                        "scope": "source.c entity.name.function.preprocessor",
                        "settings": {
                            "foreground": "#eb9b82"
                        }
                    }
                ]
            }
        },
    

    The comma between scopes makes them alternatives so the rule is being applied to source.c and to entity.name.function.preprocessor separately.

    But you want to modify (i.e., limit) the scopes – in that case you do not use a comma to separate the scopes but just a space.

    [I can’t actually duplicate your language/macro environment so I can’t test this as I usually do.]

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search