원클릭으로
vscode-commands-and-activation
Guidance for implementing and modifying VS Code commands, menus, when clauses, and activation behavior.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Guidance for implementing and modifying VS Code commands, menus, when clauses, and activation behavior.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Guidance for building, packaging, and releasing VS Code extensions with esbuild, vsce, and GitHub Actions workflows.
Guidance for declaring, reading, updating, and reacting to VS Code extension configuration and settings changes safely.
Guidance for implementing and modifying VS Code extension architecture, activation flow, disposables, and extension-host-safe patterns.
Guidance for keeping VS Code extension localization, package.nls files, README content, and changelog updates in sync.
Guidance for implementing VS Code language features such as definitions, hovers, completions, symbols, diagnostics, formatting, and related providers.
Guidance for updating VS Code extension package.json fields and contributes entries while keeping activation events, menus, and localization aligned.
| name | vscode-commands-and-activation |
| description | Guidance for implementing and modifying VS Code commands, menus, when clauses, and activation behavior. |
Commands are the primary action mechanism in VS Code. Understanding how to register, invoke, and control the visibility of commands — and how activation events relate to them — is essential for every extension.
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext): void {
// Basic command
context.subscriptions.push(
vscode.commands.registerCommand('ext.myCommand', () => {
vscode.window.showInformationMessage('Hello from myCommand!');
})
);
// Command with URI argument (context menus pass a Uri)
context.subscriptions.push(
vscode.commands.registerCommand('ext.openFile', (uri?: vscode.Uri) => {
const target = uri ?? vscode.window.activeTextEditor?.document.uri;
if (!target) { return; }
// ...
})
);
// Text editor command (receives TextEditor + TextEditorEdit)
context.subscriptions.push(
vscode.commands.registerTextEditorCommand('ext.formatSelection', (editor, edit) => {
edit.replace(editor.selection, transform(editor.document.getText(editor.selection)));
})
);
}
// Execute a built-in or contributed command
await vscode.commands.executeCommand('workbench.action.reloadWindow');
// Execute with arguments
await vscode.commands.executeCommand('vscode.open', vscode.Uri.file('/path/to/file'));
// Execute and capture return value
const items = await vscode.commands.executeCommand<vscode.SymbolInformation[]>(
'vscode.executeDocumentSymbolProvider',
document.uri
);
To hide a command from the Command Palette (useful for internal/programmatic commands):
// package.json
"menus": {
"commandPalette": [
{ "command": "ext.internalCommand", "when": "false" }
]
}
To show a command only in specific contexts:
"commandPalette": [
{ "command": "ext.fxmlCommand", "when": "resourceLangId == fxml" }
]
onLanguage:<id> — Activate when a file of a language is opened. Most common for language feature extensions.onCommand:<id> — Activate when a specific command is about to run. Useful if the extension does not need to be active before the command is invoked.workspaceContains:<glob> — Activate when the workspace contains matching files (e.g., "workspaceContains:**/pom.xml").onStartupFinished — Activate shortly after VS Code starts, without blocking startup. Use for lightweight background tasks.* — Avoid; activates on every VS Code window open.// package.json
"activationEvents": [
"onLanguage:fxml",
"onLanguage:java"
]
VS Code 1.74+:
onCommand:events for commands declared incontributes.commandsare automatically inferred — you no longer need to list them explicitly.
when ClausesSet a custom context key to control command/menu visibility dynamically:
// Set a context key
await vscode.commands.executeCommand('setContext', 'ext.myFeatureEnabled', true);
Use it in package.json:
"menus": {
"editor/title": [
{
"command": "ext.myCommand",
"when": "ext.myFeatureEnabled && resourceLangId == fxml"
}
]
}
await vscode.window.withProgress(
{
location: vscode.ProgressLocation.Notification,
title: 'Processing…',
cancellable: true,
},
async (progress, token) => {
progress.report({ message: 'Step 1', increment: 30 });
if (token.isCancellationRequested) { return; }
await doExpensiveWork();
progress.report({ message: 'Done', increment: 70 });
}
);
// Quick pick
const choice = await vscode.window.showQuickPick(['Option A', 'Option B'], {
placeHolder: 'Choose an option',
});
// Input box
const input = await vscode.window.showInputBox({
prompt: 'Enter the Scene Builder path',
validateInput: (value) => value ? undefined : 'Path cannot be empty',
});
// Open file dialog
const uris = await vscode.window.showOpenDialog({
canSelectFiles: true,
canSelectMany: false,
filters: { Executables: ['exe', 'app', ''] },
});
vscode.commands.registerCommand('ext.myCommand', async () => {
try {
await doWork();
} catch (err) {
const message = err instanceof Error ? err.message : String(err);
vscode.window.showErrorMessage(`MyExtension: ${message}`);
}
});
contributes.commands in package.json.%key% localization placeholders.activate() and pushed to context.subscriptions.when clauses are as narrow as possible.withProgress and support cancellation.