将VSCODE内置颜色选择器与JSON文件一起使用

问题描述

我正在尝试使内置的颜色选择器能够与json(webmanifest)文件一起使用,就像与vscode自己的settings.json文件一起使用的方式一样,以便在十六进制值旁边显示内联颜色块。

上一个线程建议创建一个架构并在该架构中使用format: color。我已经尝试了settings.json中https://code.visualstudio.com/docs/languages/json的文档中的示例,尽管该示例确实在我的webmanifest文档中提供了代码智能感知功能,但仍不显示颜色值。

"json.schemas": [
    {
        "fileMatch": ["*.webmanifest"],"url": "https://json.schemastore.org/web-manifest","properties": {
            "theme_color": {
                "format": "color"
            }
        }
    }
]

我找不到vscode的内置json模式来了解它是如何完成的。任何帮助将不胜感激。汤姆

更新

这包括type:object对之后才有效。仍然有很多工作要做。

"json.schemas": [
    {   
         "fileMatch": ["*.webmanifest"],"schema": {
             "type": "object","properties": {
                 "theme_color" : {
                     "type": "string","description": "toolbar colour: hex only","format": "color-hex"
                 }
             }
         }
    }
]

解决方法

这对我来说效果很好。我只更改了 *.json 文件的扩展名。 “fileMatch”采用一个数组,因此您可以根据需要添加多种文件类型。

关于为什么需要这样做的文档:

https://code.visualstudio.com/docs/languages/json#_json-schemas-and-settings

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...