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
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:
To restore all dark themes back to the way they were a couple hours ago, I replaced it with the following:
This change requires a restart to take effect.
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:From my comment on the PR here:
@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.