Add an operator to visual studio code theme in settings.json

3k views Asked by At

I'm trying to add the words and, or, not (for Lua) to the Visual Studio Code theme called "Visual Studio Dark" that is included in the vscode regular download and in the "select color theme" screen is called "Dark (Visual Studio)"

I've searched online and came about this page: Visual Studio Code Themes. This page made clear via the pictures in it that by adding a setting in the settings.json file I could get this done. I added the "editor.tokenColorCustomizations" setting as seen in the second and third picture on that page.

Two pages of linking through further I found this page: Scope Naming that explained that for adding the operator "and" to my rules I needed to have the scope: "keyword.operator.word".

I then used a colour picker online to get the specific colour that I needed from a picture of syntax highlighting that has the code I wanted. (I couldn't find the file that defines this but that would be a second question.)
This is what I came up with:

"editor.tokenColorCustomizations": {
    "textMateRules": [
        {
            "scope": "keyword.operator.word",
            "settings": {
                "foreground": "#569BD2"
        }
    ]
}

But after saving the file, closing the window and opening it again this is what I see:

It does not seem to work

1

There are 1 answers

1
Gama11 On BEST ANSWER

As the Developer: Inspect TM scopes command shows, the and, or and not operators don't use the keyword.operator.word scope - instead, they use keyword.operator.lua:

Consequently, the following works:

"editor.tokenColorCustomizations": {
    "textMateRules": [
        {
            "scope": "keyword.operator.lua",
            "settings": {
                "foreground": "#569BD2"
            }
        }
    ]
}

Note that the scope name doesn't specify what kind of operator it is, so this will apply to all operators, not just and, or and not. The only way to change this is to modify the language grammar / TmLanguage file itself, which is shipped with VSCode in the case of Lua.