Development
vscode-feature-command
Add a new command to the VS Code extension.
Add a new command to the VS Code extension.
Use this skill when the user wants to add a new functional command (e.g., "Hello World", "Format Text") to the extension.
Adding a command requires updates to two files: package.json and src/extension.ts.
package.jsonAdd the command definition to the contributes.commands array.
// package.json
{
"contributes": {
"commands": [
{
"command": "extension.myCommand", // Unique ID
"title": "My Extension: Do Something" // Display Name
}
]
}
}
src/extension.tsRegister the command in the activate function.
// src/extension.ts
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
// ... existing code ...
let disposable = vscode.commands.registerCommand('extension.myCommand', () => {
// Implementation logic here
vscode.window.showInformationMessage('Command executed!');
});
context.subscriptions.push(disposable);
}
extensionName.actionName format to avoid conflicts.async () => { await ... }.