Search code examples
javascriptvisual-studio-codetextmatetmlanguage

VS Code - highlight some variables with TextMate


VS Code 1.15 added support for TextMate grammar rules. I want to highlight some variables in JavaScript with these rules: self, me. How can I do this?


Solution

  • Short answer: you can't.

    I'm assuming you're referring to the new editor.tokenColorCustomizations setting. This setting only allows you to change the colors associated with specific scopes that the TextMate grammar already defines. self and me are not treated specially by the JS gramar, they use the same variable.other.readwrite.js scope as any other variable:

    Contrast this with the this keyword: It has its own unique variable.language.this.js scope, so we could use the setting to color this red:

    "editor.tokenColorCustomizations": {
        "textMateRules": [
            {
                "scope": "variable.language.this.js",
                "settings": {
                    "foreground": "#FF0000"
                }
            }
        ]
    }