How can I add a command to VS Code?

86 views Asked by At

We would like to contribute to the VS Code GitHub and would like to add function to some commands. However, we could not find where the commands are defined. Could anyone tell me which dir these code are in?

We tried the keybinding and workbench. But we cannot find the definition of "ctrl + p" (command palette) which we would like to edit.

1

There are 1 answers

0
starball On

For builtin VS Code commands, you want to implement Action2 and then pass your implementation to a call to registerAction2- both of which are defined in the file microsoft/vscode/src/vs/platform/actions/common/actions.ts. registerAction2- among other things- makes the necessary calls to CommandsRegistry.registerCommand, MenuRegistry.appendMenuItem (which makes the command available from the command palette), and KeybindingsRegistry.registerKeybindingRule).

Note that if you don't insist on making the command one builtin to VS Code, you can just do it through an extension by contributing a command in the extension manifest (contributes.commands) and then registering an implementation of the command (see vscode.commands.registerCommand). You can find VS Code's handler for command contributions in its call to commandsExtensionPoint.setHandler in src/vs/workbench/services/actions/common/menusExtensionPoint.ts, which you'll notice makes a call to MenuRegistry.addCommand so the command is accessible from the command palette.