Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 314
matjojo Avatar asked Sep 04 '17 09:09

matjojo


People also ask

How do you add a command palette in VS code?

The most important key combination to know is Ctrl+Shift+P, which brings up the Command Palette. From here, you have access to all of the functionality of VS Code, including keyboard shortcuts for the most common operations.


1 Answers

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.

like image 75
Gama11 Avatar answered Sep 28 '22 01:09

Gama11