【问题标题】:How to add "show preview" button to VS Code extension?如何将“显示预览”按钮添加到 VS Code 扩展?
【发布时间】:2020-05-25 08:13:25
【问题描述】:

我有一个分析自定义 JSON 和 YAML 文件的 VS Code 扩展。所以在项目的package.json中,有这样的:

    "activationEvents": [
        "onLanguage:yaml",
        "onLanguage:json",
        "onCommand:extension.sidePreview"
    ],

每当有人打开其中一个文件时,我想在编辑器的右上角添加一个“显示预览”图标:

于是我在项目中添加了对应的icon资源,并且:

"contributes": {
        "commands": [
            {
                "command": "extension.sidePreview",
                "title": "Preview file",
                "icon": {
                    "dark": "./resources/open-preview-dark.svg",
                    "light": "./resources/open-preview-light.svg"
                }
            }
        ],
        "menus": {
            "editor/title": [
                {
                    "command": "extension.sidePreview",
                    "when": "true"
                }
            ]
        },

但这不起作用...我没有看到任何图标。

我还想确保此按钮和命令仅在 server.ts 中的函数 isCustomFile 返回 true 时可用。有没有办法做到这一点?

【问题讨论】:

    标签: visual-studio-code vscode-extensions language-server-protocol


    【解决方案1】:

    那是因为您在menus 下添加了错误的部分。

    您应该改为添加editor/title

    Reference

    【讨论】:

    • 嘿,谢谢!现在我看到了命令,但没有看到图标:/我粘贴了我在问题中的内容
    • 哦,我必须添加group: navigation
    猜你喜欢
    • 2019-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-09
    • 2021-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多