问题
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