我正在尝试更改 Python 中
==
和 !=
比较运算符的颜色,但即使正确设置了 textMate 规则(如下图所示),颜色也不会改变,并且范围具有我以前从未见过的奇怪的覆盖属性。
接下来,我四处搜索,发现这可能是由语义突出显示引起的,事实上,当关闭它时,它会停止覆盖 textMate (也很奇怪地注意到,它只在语义突出显示覆盖的特定范围内),所以我尝试将以下规则添加到我的
settings.json
并将语义突出显示设置为 `configuredByTheme:
"editor.semanticTokenColorCustomizations": {
"[One Dark Pro Flat]": {
"rules": {
"keyword.operator.comparison.python": "#00cf80"
}
}
}
但这没有用,现在我没有主意了。有人可以帮我吗?
当语义突出显示由语言支持扩展提供,并且启用语义突出显示(默认设置
"editor.semanticHighlighting.enabled": "configuredByTheme"
),并且为标记提供语义突出显示时,它将优先于任何基于 TextMate 的语法突出显示进行突出显示。这正是这里发生的事情。
Python 扩展提供的语义标记是
operator
,带有修饰符 overridden
(==
运算符 被 test_matrix
变量的类覆盖)。要么禁用语义突出显示(可能不是您想要的),要么将以下内容添加到您的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",
},
},
},
},
以上内容适用于 Python 文件中的任何 operator
语义标记。如果您想单独为覆盖的运算符着色,请使用
operator.overridden:python
代替。另请参阅https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide。