VS Code extension: Hide commands from command palette

不想你离开。 提交于 2019-12-22 07:04:48

问题


Background:

I'm currently working on a simple VS Code extension that will provide dynamically set command variables to my build & debug tasks. The plan is to have a series of attributes that will be accessible in launch.json, etc. through the "${command:extension.myCommand}" syntax.

Registering commands like this is as simple as adding an entry to the package.json file, e.g.:

"contributes": {
    "commands": [
        {
            "command": "extension.myCommand",
            "title": ""
        }
    ]
}

and implementing the corresponding commands in my main extension file:

let disposable = vscode.commands.registerCommand('extension.myCommand', () => {
    return "dynvar";
});
context.subscriptions.push(disposable);

The Problem:

Unfortunately these commands now also appear in the command palette, and as they don't have any interactive use that's quite annoying.

Question:

Is there any way I can hide commands contributed through extensions from VS Code's command palette?


回答1:


If you don't need to associate an "icon" or a "title" with your command, you can simply omit it from "commands" - commands that are not listed there can still be called, as long as they have been registered via vscode.commands.

Otherwise, you can use the following trick to hide it from the command palette:

"contributes": {
    "menus": {
        "commandPalette": [
            {
                "command": "extension.myCommand",
                "when": "false"
            }
        ]
    }
}



回答2:


"contributes": {
"commands": [
    {
        "command": "extension.myHiddenCommand",
        "title": "Compile folder"
    }
],
"menus": {
    "commandPalette": [
        {
            "command": "extension.myHiddenCommand",
            "when": "false"
        }
    ]
}

}



来源:https://stackoverflow.com/questions/55270915/vs-code-extension-hide-commands-from-command-palette

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!