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.
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 which is marked as being in the July 2023 release milestone (implementation now completed).
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 trigger suggestions inside the [] if you need help finding your theme's name/ID
"textMateRules": [
{
"scope": "string.quoted.docstring", // use string.quoted.docstring.multi.python if you only want it to apply for python.
"settings": {
"foreground": "#FF0000", // TODO
}
}
]
}
}
At time of writing, there are issues open for bugs regarding the schema loading for various settings json files, which leads to the trigger suggestions
feature breaking. In case the trigger suggestions
feature does not work, here is a list of theme aliases:
If these do not work, you can try an asterisk "[*]"
or remove the theme scoping entirely (but know that hardcoding a colour from one theme for all themes will not achieve the desired behaviour for all themes):
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"name": "Docstrings",
"scope": "string.quoted.docstring",
"settings": {
"foreground": "#CE9178"
}
}
]
}