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?
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"
}
]
}
}
The following snippet illustrates how to hide a command registered as 'extension.myHiddenCommand':
"contributes": {
"commands": [
{
"command": "extension.myHiddenCommand",
"title": "Compile folder"
}],
"menus": {
"commandPalette": [
{
"command": "extension.myHiddenCommand",
"when": "false"
}]
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With