【问题标题】:Using vscode built-in colour picker with JSON files使用带有 JSON 文件的 vscode 内置颜色选择器
【发布时间】:2020-11-11 23:53:37
【问题描述】:

我正在尝试让内置颜色选择器与 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 visual-studio-code color-picker


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-23
      相关资源
      最近更新 更多