首页 > 解决方案 > 如何将 vscode 贡献的设置设置为颜色类型?

问题描述

我创建了一个简单的 VS Code 扩展,它提供了一组配置设置。这是来自的块的简化示例package.json

"configuration": {
    "type": "object",
    "title": "abc",
    "properties": {
        "xyz": {
            "type": [
                "array"
            ],
            "items": {
                "title": "Custom patterns to highlight.",
                "type": "object",
                "properties": {
                    "foreground": {
                        "pattern": "^[^$|^\\s]",
                        "type": "string",
                        "title": "The color.",
                        "description": "The foreground color that will be used for highlighting."
                    }
                }
            }
        }
    }
}

有没有办法将设置的类型foreground设置为颜色而不是任何字符串?似乎没有颜色类型或类似的。

如果设置编辑器能够理解它是一种颜色并像本节中那样显示颜色选择器,那就太好了:

在此处输入图像描述

标签: visual-studio-codevscode-settingsvscode-extensions

解决方案


您需要添加格式属性:

"myconfig.someColor": {
    "type": "string",
    "format": "color-hex",
    "scope": "resource",
    "description": "Some Color"
}

我为此找到了一些文档:

https://github.com/microsoft/vscode/tree/master/extensions/json-language-features/server


推荐阅读