I'm trying to change the color of the the ==
and !=
comparison operators in Python, but even though textMate rules is appropriately set up, like it can be seen in the image below, the color doesn't change, and the scope has this weird overridden attribute that I've never seen before.
Next, I searched around and found that this could be caused by semantic highlighting, and indeed, when turning it off, it stops overriding textMate (it's curious to note as well that it only very select scopes that semantic highlighting is overriding), so I tried adding the following rule to my settings.json
and set semantic highlighting to `configuredByTheme:
"editor.semanticTokenColorCustomizations": {
"[One Dark Pro Flat]": {
"rules": {
"keyword.operator.comparison.python": "#00cf80"
}
}
}
But that didn't work, and now I'm out of ideas. Can someone please help me?
When semantic highlighting is contributed by a language support extension, and semantic highlighting is enabled (default setting "editor.semanticHighlighting.enabled": "configuredByTheme"
), and semantic highlighting is contributed for a token, it will take precedence for highlighting over any TextMate-based syntax highlighting. That's exactly what's happening here.
The semantic token being contributed by the Python extension is operator
, with the modifier overridden
(the ==
operator is overridden by the class of your test_matrix
variable). Either disable semantic highlighting (probably not what you want), or add the following to your settings.json:
"editor.semanticTokenColorCustomizations": {
"[Your Theme Name Here]": { // remove wrapper to apply regardless of colour theme.
"rules": {
"operator:python": { // remove ":python" to apply regardless of language
"foreground": "#FF0000", // TODO
// "fontStyle": "bold",
},
},
},
},
The above will apply to any operator
semantic token in Python files. If you want to colour overridden operators separately, use operator.overridden:python
instead. See also https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide.