skip to Main Content

I have no idea how this happened. Nothing I do with themes seems to do anything. Before I restarted VS Code, I had the "Dark modern" theme selected, and Python docstrings were exactly the same color as other strings. After I restarted, the "Dark modern" theme was still selected, but now docstrings are an ugly, dark green color. Toggling between themes does not restore the original color. Manually modifying the theme json file does nothing, and this nasty color is not in any of the theme files. Disabling and/or re-enabling extensions has no effect with the exception that disabling the Python extension removes several colors from syntax highlighting, but not the dark green. Using a venv or not has no effect.

Any idea what happened or how to fix this?

Edit: I found the culprit. This guy decided to just change the theme color. The task remains to fix it back to the way it was before this change.

Edit 2: VS Code does not seem to have a way to distinguish between block comments and docstrings. There is a semantic, non-syntactic difference between these in the Python language. To some extent, the problem is incurable without the VS Code team updating how they handle this semantic difference: it will incorrectly highlight docstrings and block comments identically, so the answer is to choose between wrong behaviors.

3

Answers


  1. Chosen as BEST ANSWER

    I figured it out. The color is coming from the dark_vs.json theme file, whether or not you have that theme selected. The problem was that in the "tokenColors" array was the following object:

            {
                "name": "Comments",
                "scope": ["comment", "string.quoted.docstring"],
                "settings": { "foreground": "#6a9955" }
            },
    

    To restore all dark themes back to the way they were a couple hours ago, I replaced it with the following:

            {
                "name": "Docstrings",
                "scope": ["string.quoted.docstring"],
                "settings": { "foreground": "#ce9178" }
            },
            {
                "name": "Comments",
                "scope": ["comment"],
                "settings": { "foreground": "#6a9955" }
            },
    

    This change requires a restart to take effect.


  2. Note: As mentioned in the question post, this change was made in PR all color themes: treat comment docstrings as comments too #182162, and a PR has been made requesting to revert the change at Revert Python docstring color #184938.

    First find out what colour your theme uses for strings, which you can do by writing a string literal and then using the Developer: Inspect Editor Tokens and Scopes command, and then add the following to your settings.json file:

    "editor.tokenColorCustomizations": {
       "[Theme Name Here]": { // TODO
          "textMateRules": [
             {
                "scope": "string.quoted.docstring", // use string.quoted.docstring.multi.python if you only want it to apply for python.
                "settings": {
                   "foreground": "#FF0000", // TODO
                }
             }
          ]
       }
    }
    
    Login or Signup to reply.
  3. From my comment on the PR here:

    To help people go back:

    For anyone wishing to customize your theme to go back to how it was for your syntax highlighter, read my answer here to learn how to do that. It contains info about finding the names and colors of sections you like and how to change the ones you don’t:

    How to subdue Python block comment strings in VSCode in order to look like Sublime Text’s Monokai

    In my link above, I explain how to use the token and scope inspector, and then I say:

    Use this technique to customize other scopes and colors to your liking, or to see what colors and formatting other scopes currently have if you want to copy them.

    @starball also has a great answer to this question. With that answer plus the info. and screenshots in my link above, everyone can tweak their syntax highlighters as desired.


    By the way, I am the one who created that PR, and VSCode’s maintainers are the ones who requested that I massively expand my PR to cover all docstrings, not just Python docstrings, and all syntax highlighters, not just the Monokai syntax highlighter I was using. The idea is to make docstring comments, which are really more in the category of comments, not strings, be treated by the syntax highlighters the same as comments, not strings. VSCode agreed, and asked me to expand my PR.

    But overall, I think though now painful for some, the change is really a benefit to most, and the right default behavior for all going forward.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search