vscode 的语义标记着色不适用于字符串
vscode's semantic token coloring not working for strings
我在 settings.json 中有这些行:
"editor.semanticTokenColorCustomizations": {
"enabled": true,
"rules": {
"string": { "foreground": "#ff0000" }, // doesn't work
"*.declaration": { "bold": true }, // works
}
},
注意里面有两条规则,虽然第二条有效,但第一条(为“字符串”着色的规则)无效:
现在,根据 here and here,“字符串”令牌确实存在,因此它应该可以工作(除非我遗漏了什么)。
另一种猜测是,可能是主题妨碍了我,但我卸载了所有非默认主题,但结果是一样的(声明为粗体,而字符串未着色)。
P.S:我没有使用 textmate 规则,因为当我尝试标记检查时,它会以更详细的方式为所有内容建议这么多标记,但我不想写那么多规则,当我想要的只是为所有字符串着色的规则时。
编辑: 我决定也试试 Textmate 方式,字符串的范围是 string.quoted.double
,但这次不能和之前的规则混在一起!所以现在着色规则起作用了,而样式不起作用:
"editor.tokenColorCustomizations": {
"enabled": true,
"rules": {
"*.declaration": { "bold": true }, // doesn't work
},
"textMateRules": [
{
"scope": "string.quoted.double",
"settings": {
"foreground": "#ff0000", // works
},
}
],
},
最后,同时使用 textmate 和语义自定义,并“分别”编写这两个规则似乎可行(textmate 方法是 visual studio 代码的较旧(原始)标记化方法,而语义最近添加了一个):
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "string.quoted.double",
"settings": {
"foreground": "#8b7a69"
}
}
]
},
"editor.semanticTokenColorCustomizations": {
"enabled": true,
"rules": {
"*.declaration": { "bold": true },
}
},
我在 settings.json 中有这些行:
"editor.semanticTokenColorCustomizations": {
"enabled": true,
"rules": {
"string": { "foreground": "#ff0000" }, // doesn't work
"*.declaration": { "bold": true }, // works
}
},
注意里面有两条规则,虽然第二条有效,但第一条(为“字符串”着色的规则)无效:
现在,根据 here and here,“字符串”令牌确实存在,因此它应该可以工作(除非我遗漏了什么)。
另一种猜测是,可能是主题妨碍了我,但我卸载了所有非默认主题,但结果是一样的(声明为粗体,而字符串未着色)。
P.S:我没有使用 textmate 规则,因为当我尝试标记检查时,它会以更详细的方式为所有内容建议这么多标记,但我不想写那么多规则,当我想要的只是为所有字符串着色的规则时。
编辑: 我决定也试试 Textmate 方式,字符串的范围是 string.quoted.double
,但这次不能和之前的规则混在一起!所以现在着色规则起作用了,而样式不起作用:
"editor.tokenColorCustomizations": {
"enabled": true,
"rules": {
"*.declaration": { "bold": true }, // doesn't work
},
"textMateRules": [
{
"scope": "string.quoted.double",
"settings": {
"foreground": "#ff0000", // works
},
}
],
},
最后,同时使用 textmate 和语义自定义,并“分别”编写这两个规则似乎可行(textmate 方法是 visual studio 代码的较旧(原始)标记化方法,而语义最近添加了一个):
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "string.quoted.double",
"settings": {
"foreground": "#8b7a69"
}
}
]
},
"editor.semanticTokenColorCustomizations": {
"enabled": true,
"rules": {
"*.declaration": { "bold": true },
}
},