最佳答案
自从我发布这个问题以来,semanticTokenColorCustomizations 和范围的工作方式已经有了一些更新,因此我能够使用以下设置突出显示全局变量:
"editor.semanticTokenColorCustomizations": {
"enabled": true,
"rules": {
"variable": {"bold": true}, // Bold all variables
"variable.local": {"bold": false}, // Un-bold local variables
"variable.defaultLibrary": {"bold": false}, // Un-bold defaultLibrary "variables" such as "console"
"property.declaration": {"bold": false}, // Un-bold object property value shorthand
}
},
但是,这似乎只突出了已声明(或在同一文件中声明)的全局变量。解决方法是添加 editor.tokenColorCustomizations
抓取语义突出显示未选择的任何变量。 "editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "variable.other.readwrite",
"settings": {
"fontStyle": "bold"
}
}
]
},
这导致以下结果:这是相当未经测试的,旨在为 JavaScript 工作,但我希望它是 future 可能需要它的任何人的起点。
关于javascript - 如何在 VSCode 中突出显示全局变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58959094/