Search code examples
pythonvisual-studio-codethemessyntax-highlightingpylance

How to fix pylance syntax highlighting showing wrong color for self and cls python class parameters in VSCode with enabled default theme


I have encountered this issue when I use Pylance and syntax highlighting is enabled for python in the VSCode with default or the visual studio theme.

self and cls parameter are LightSkyBlue color like other parameters before

It should be like this:

should be this


Solution

  • Added the color code inside the settings.json file for the dark themes I use.

    // correct color self and cls python
    "editor.semanticTokenColorCustomizations": {
        "[Default Dark+]": {
            "rules": {
                "selfParameter": "#569CD6",
                "clsParameter": "#569CD6"
            },
        },
        "[Visual Studio Dark]": {
            "rules": {
                "selfParameter": "#569CD6",
                "clsParameter": "#569CD6"
            },
        },
        "[Default Dark Modern]": {
            "rules": {
                "selfParameter": "#569CD6",
                "clsParameter": "#569CD6"
            },
        }
    },
    

    Add theme settings based on what theme you are using. for example, I just changed my theme to [Default Dark Modern] and then added the color settings.

    These two issues on pylance and vscode github repository helped: