如何在扩展中使用 VSCode 产品图标作为命令

How to use VSCode product icon for command in extension

我正在尝试向运行我的命令的 'editor/title' 部分添加一个按钮。使用我当前的配置,通过单击 3 个按钮展开菜单时会出现我的命令名称。我想要的是显示一个图标(如拆分编辑器按钮),它运行我的命令。

从文档中我发现应该可以为图标提供 svg 文件,但我更喜欢使用 product icons 中的图标。这样图标就可以随主题变化了。

这可能吗,还是我配置不正确?

这是我目前的配置:

"contributes": {
    "commands": [
        {
            "command": "my-extension.my-command"
            "title": "My Command",
            "icon": "preview" // <-- this refers to the icon from 'product icons'
        }
    ],
    "menus": {
        "editor/title": [
            {
                "when": "resourceExtname == .xyz",
                "command": "my-extension.my-command"
            }
        ]
    }
}

这应该有效:

"contributes": {
    "commands": [
        {
            "command": "my-extension.my-command"
            "title": "My Command",
            "icon": "$(preview)" // <-- the syntax for using a 'product icon' is $(iconIdentifier)
        }
    ],
}