It depends on whether the language support extension you're using uses TextMate grammars or semantic highlighting (see also https://code.visualstudio.com/api/language-extensions/syntax-highlight-guide#tokenization).
For language-support extensions using TextMate-based highlighting
VS Code seems to define some generic scope names (comment
, comment.block
, comment.block.documentation
, and comment.line
), but from my observation, not every language extension (even counting only builtin extensions) adheres to this convention.
You need to figure out what TextMate scopes it defines for comments, which you can do by using the token scope inspector- use the Developer: Inspect Editor Tokens and Scopes
command in the command palette. It will open an inspector widget that follow the cursor and show what TextMate scopes match for the token under the cursor. Once you know what tokens exist, pick whichever one(s) is the most suitable and write a corresponding rule in the editor.tokenColorCustomizations
setting in your settings.json file.
If you want to get a quick overview of possibly relevant scope names, here's a UNIX command you could use to scan a directory for TextMate grammars and pick out scope names that contain the substring "comment" in their name: jq '.' $(find . -name '*.tm*') | command grep '"name".*comment' | awk '{$1=$1};1' | sort | uniq
. You could run this from your VS Code installation's directory to get such scope names for the grammars of builtin extensions, or from your .vscode/extensions/
directory in your user home directory to scan for scopes from grammars of non-builtin extensions that you manually installed. Then you could do a pass to check each of those out and see if it's something you want to modify.
Then you would write something like this in your settings.json file:
"editor.tokenColorCustomizations": {
"[name of your current colour theme here]": { // optionally remove this colour theme wrapper to apply the customization for all themes
"textMateRules": [{
"scope": "commentscope1, commentscope2, commentscope3, ...",
"settings": {
"foreground": "#ff0000", // TODO
},
}],
},
},
For language-support extensions using Semantic highlighting
For language support extensions that instead use semantic highlighting, it's much simpler. Instead of the editor.tokenColorCustomizations
setting, use the editor.semanticTokenColorCustomizations
setting, and write a rule for the comment
token type (one of the standard token types). Ex.
"editor.semanticTokenColorCustomizations": {
"[name of your current colour theme here]": { // optionally remove this colour theme wrapper to apply the customization for all themes
"rules": {
"comment": "#ff0000", // TODO
},
},
},