Home > OS >  How to do syntax highlighting of methods in vs code (Python)
How to do syntax highlighting of methods in vs code (Python)

Time:06-14

When I set up the theme in vs code I chose "Monokai Dark Soda", but the problem is that it doesn't highlight methods in a separate color (just white). I tried to solve it in the settings.json file and used the following code:

"editor.tokenColorCustomizations": {
    "textMateRules": [
        {
            "scope": "entity.name.method",
            "settings": {
                "foreground": "#66D9EF",
            }
        },

        {
            "scope": "entity.name.function.member",
            "settings": {
                "foreground": "#66D9EF",
            }
        }
    ]
}

and:

"editor.semanticTokenColorCustomizations": {
    "[Monokai Dark Soda]": {
        "rules": {
            "method": "#66D9EF"
        }
    }
}

But none of these solutions work either together or separately, although in all other respects, customization works fine. At the same time, choosing from ready-made themes in the market, the methods are highlighted in a separate color, that is, it is possible to implement. But for some reason I can't.

How i want: with method highlight

How it works: without method highlight

CodePudding user response:

By default, the "MagicPython" module is used for python syntax highlighting in vs code. To highlight methods, you should update this module in the store (just in case) and add the following code to settings.json:

"editor.tokenColorCustomizations": {
    "textMateRules": [
        {
            "scope": "meta.function-call.generic",
            "settings": {
                "foreground": "YOUR_COLOR" // choose your color
            }
        }
    ]
}

This will also colorize any callable object (with "( )" ) and functions in particular, but I didn't find a separate solution for methods in the scopes list.

If this solution did not help you or you want to configure it yourself, then here is a link to the official MagicPython repository with all scopes: MagicPython scopes

  • Related