如何在 VS Code 的扩展程序中隐藏调色板菜单中的命令 [英] How do I hide a command in the palette menu from my extension in VS Code

查看:33
本文介绍了如何在 VS Code 的扩展程序中隐藏调色板菜单中的命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从 this 页面开始构建 VS Code 扩展.现在我想在我运行它后将命令 extension.timerStart 隐藏在调色板菜单中.我已经阅读了 this 页面,但没有帮助.我有以下 package.json 的代码.如何使 varFromMyExtension===false 部分工作?

I am building a VS Code extension starting from this page. Now I want to hide in the palette menu the command extension.timerStart after I run it. I have read this page, didn't helped. I have the code bellow for package.json. How do I make the varFromMyExtension===false part work?

  "contributes": {
    "commands": [
      {
        "command": "extension.timerStart",
        "title": "Timer Start"
      }
    ],
    "menus": {
      "commandPalette": [
        {
          "command": "extension.timerStart",
          "when": "varFromMyExtension===false"
        }
      ]
    }

推荐答案

我认为不可能在 when 子句中直接从扩展访问变量.但是,您可以访问 settings.json 的任何配置.

I think it is not possible to access variables from your extension directly in a when clause. However you can access any configuration of the settings.json.

来自文档(位于章):

注意:您可以在此处使用任何计算结果为布尔值且带有前缀 "config." 的用户或工作区设置.

Note: You can use any user or workspace setting that evaluates to a boolean here with the prefix "config.".

因此,当您的扩展程序提供 boolean 配置时 称为 varFromMyExtension 您应该能够在 when 子句中使用它.然后,此配置也可以以编程方式操作.

So when your extension contributes a boolean configuration called varFromMyExtension you should be able to use it in the when clause. This configuration then can be manipulated programmatically, too.

所以你的 package.json 可能会包含这样的内容(未测试):

So your package.json would probably contain something like this (not tested):

"contributes": {
    "commands": [
        {
            "command": "extension.timerStart",
            "title": "Timer Start"
        }
    ],
    "menus": {
        "commandPalette": [
            {
                "command": "extension.timerStart",
                "when": "!config.myextension.varFromMyExtension"
            }
        ]
    },
    "configuration": {
        "type": "object",
        "title": "Indicates whether ...",
        "properties": {
            "myextension.varFromMyExtension": {
                "title": "My title.",
                "description": "My description",
                "type": "boolean",
                "default": false,
                "pattern": "(true|false)"
            }
        }
    }
}

但请记住,用户也可以查看和编辑此设置.

这篇关于如何在 VS Code 的扩展程序中隐藏调色板菜单中的命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆