vscode-extension-guide-en Skill
VS Code 扩展开发英文指南——从脚手架搭建到 Marketplace 发布。涵盖 webview 模式、CSP 安全、TreeView、测试、打包、AI 定制和故障排查。改编自 aktsmm/agent-skills,并针对 VS Code 1.74+ API 做了修正。
安装方式:把技能目录放入 ~/.claude/skills/(Claude Code)或在 claude.ai 设置中启用;也可复制右侧安装命令一键添加。
技能指令原文(SKILL.md)
VS Code extension guide
Use the references below for extension APIs, testing, publishing, and troubleshooting.
Quick start
# Scaffold without a global install
npx --package yo --package generator-code -- yo code
# Or minimal manual setup
mkdir my-extension && cd my-extension
npm init -y && npm install -D typescript @types/vscode
Project structure
my-extension/
├── package.json # Extension manifest
├── src/extension.ts # Entry point
├── out/ # Compiled JS (gitignore)
├── images/icon.png # At least 128x128 PNG for Marketplace
└── .vscodeignore # Exclude files from VSIX
Building and packaging
npm run compile # Build once
npm run watch # Watch mode (F5 to launch debug)
npx @vscode/vsce package # Creates .vsix
Done criteria
- [ ] Extension activates without errors
- [ ] All commands registered and working
- [ ] Inspect VSIX contents with
npx @vscode/vsce lsand confirm its size is appropriate - [ ] README.md includes Marketplace/GitHub links
Quick troubleshooting
| Symptom | Fix |
| --------------------- | --- |
| Extension not loading | Check activation events and engines.vscode; contributed commands/views auto-activate since VS Code 1.74 |
| Command not found | Match command ID in package.json and registerCommand |
| Shortcut not working | Check the when clause and keybinding conflicts |
References
| Topic | Reference |
| ------------------- | -------------------------------------------------------------------- |
| AI Customization | references/ai-customization.md |
| Code Review Prompts | references/code-review-prompts.md |
| TreeView | references/treeview.md |
| Webview | references/webview.md |
| Testing | references/testing.md |
| Publishing | references/publishing.md |
| Troubleshooting | references/troubleshooting.md |
| Extension management | Install, disable, update, and manage extensions |
Best practices
Naming consistency
Unify package name, setting keys, command IDs, and view IDs before publishing:
| Item | Example |
|------|---------|
| Package name | copilot-scheduler |
| Setting key | copilotScheduler.enabled |
| Command ID | copilotScheduler.createTask |
| View ID | copilotSchedulerTasks |
Centralised notification handling
type NotificationMode = "toast" | "silentStatus";
function getNotificationMode(): NotificationMode {
const config = vscode.workspace.getConfiguration("myExtension");
return config.get<NotificationMode>("notificationMode", "toast");
}
function notifyInfo(message: string, timeoutMs = 4000): void {
const mode = getNotificationMode();
switch (mode) {
case "silentStatus":
vscode.window.setStatusBarMessage(message, timeoutMs);
break;
default:
void vscode.window.showInformationMessage(message);
}
}
function notifyError(message: string, timeoutMs = 6000): void {
const mode = getNotificationMode();
if (mode === "silentStatus") {
vscode.window.setStatusBarMessage(`⚠ ${message}`, timeoutMs);
console.error(message);
return;
}
void vscode.window.showErrorMessage(message);
}
Expose a notificationMode setting so users can control how notifications are delivered.