vscode中黄色波浪线分两类:lsp诊断警告(由workbench.colorcustomizations控制)和语法非法标记(由editor.tokencolorcustomizations控制),可通过developer: inspect editor tokens and scopes查看scope中含warning或invalid来区分。

怎么判断警告波浪线属于哪一类颜色系统
VSCode 里黄色波浪线可能来自两个完全不相干的机制:一种是 ESLint、Pylance、TypeScript 等语言服务器报告的 warning 级别诊断(LSP diagnostic),另一种是语法层面硬错误(比如 consol.log() 拼错)触发的 invalid token。前者受 workbench.colorCustomizations 控制,后者必须用 editor.tokenColorCustomizations。光标停在波浪线上,按 Ctrl+Shift+P → Developer: Inspect Editor Tokens and Scopes,看 scope 链里有没有 warning 或 invalid —— 有 warning 就走 LSP 路径,有 invalid 就走语法路径。
改 ESLint / TypeScript 的 warning 波浪线颜色
这类波浪线颜色由 workbench.colorCustomizations 中的 editorWarning.foreground 决定,它同时控制波浪线本身、Problems 面板里的文字、悬停提示中的警告文本。不生效?常见原因有:
- 配置写到了用户级
settings.json,但项目里启用了工作区设置(.vscode/settings.json),后者会覆盖前者 - 当前文件右下角语言模式不是
javascript或typescript,而是plaintext或json,导致语言服务器根本没启动 - ESLint 插件未监听到配置变更,需执行
ESLint: Restart ESLint Server或重新打开文件夹
正确配置示例(加到 settings.json):
{
"workbench.colorCustomizations": {
"editorWarning.foreground": "#e8a33e",
"editorWarning.border": "#00000000"
}
}
改 JSON 注释警告这类“语法警告”的波浪线颜色
像 JSON with Comments 模式下写的注释被标黄,或者 if x=1: 在 Python 文件里被标黄,这类不是语言服务器报的 warning,而是编辑器词法分析标记的 invalid.deprecated 或 invalid.illegal scope。它们完全无视 editorWarning.foreground,只能靠 editor.tokenColorCustomizations。
- 先用
Developer: Inspect Editor Tokens and Scopes确认最精确的 scope,比如invalid.deprecated.json - scope 写得越细,影响范围越小;只写
invalid会让所有非法字符(如不可见 Unicode)都变色 - 改完必须
Developer: Reload Window,热更新不重绘波浪线
示例(针对 JSON 注释警告):
{
"editor.tokenColorCustomizations": {
"textMateRules": [
{
"scope": "invalid.deprecated.json",
"settings": {
"foreground": "#e8a33e"
}
}
]
}
}
为什么改了颜色还是黄得不明显
深色主题下默认的黄色(如 #cca700)在背景上对比度太低,人眼很难第一时间捕捉。这不是亮度问题,是色相和明度组合导致的视觉惰性。直接换琥珀色(#e8a33e)或橙红(#f75464)能显著提升识别效率。另外注意:editorWarning.foreground 不控制边框色,如果悬停提示框边框太抢眼,顺手加上 "editorWarning.border": "#00000000" 隐藏掉——这个细节几乎没人提,但真会影响阅读节奏。











