Communityコーディング&開発github.com

VS Code 拡張機能開発ガイド

VS Code 拡張機能の開発に関する英語ガイド。スキャフォールディングからマーケットプレイス公開までをカバー。WebView パターン、CSP セキュリティ、TreeView、テスト、パッケージング、AI カスタマイズ、トラブルシューティングなどを解説。aktsmm/agent-skills を VS Code 1.74+ API 向けに修正・翻案。

VS Code 拡張機能開発ガイド とは?

このスキルは、VS Code 拡張機能の開発を支援する包括的なガイドです。初心者から経験者まで、スキャフォールディング、コマンドや設定の追加、マーケットプレイスへの公開までの全工程をカバーします。主に Claude Code, Cursor, Codex などの AI エージェント上で動作し、`yo code` によるプロジェクト生成、TypeScript での開発、`vsce` によるパッケージングと公開といった具体的な手順を提供します。また、WebView、TreeView、CSP セキュリティ、テスト、AI カスタマイズ、トラブルシューティングなど、実践的なトピックについて詳細なリファレンスが用意されています。さらに、一元化された通知処理や命名規則の統一といったベストプラクティスも含まれており、拡張機能の品質と一貫性を高めるための実用的なアドバイスを提供します。

対応~Claude Code~Codex CLI~Cursor
npx skills add lewiswigmore/agent-skills

Installed? Explore more コーディング&開発 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

VS Code 拡張機能ガイド

VS Code 拡張機能を作成、開発、公開します。

使用タイミング

  • VS Code 拡張機能、拡張機能開発、vscode プラグイン
  • ゼロから新しい VS Code 拡張機能を作成する場合
  • 拡張機能にコマンド、キーバインド、設定を追加する場合
  • VS Code マーケットプレイスに公開する場合

クイックスタート

# 新しい拡張機能をスキャフォールディング(推奨)
npm install -g yo generator-code
yo code

# または最小限の手動セットアップ
mkdir my-extension && cd my-extension
npm init -y && npm install -D typescript @types/vscode

プロジェクト構造

my-extension/
├── package.json          # 拡張機能マニフェスト(重要)
├── src/extension.ts      # エントリポイント
├── out/                  # コンパイル済みJS(gitignore)
├── images/icon.png       # マーケットプレイス用 128x128 PNG
└── .vscodeignore         # VSIX から除外するファイル

ビルドとパッケージング

npm run compile      # 一度ビルド
npm run watch        # ウォッチモード(F5 でデバッグ起動)
npx @vscode/vsce package   # .vsix を作成

完了条件

  • 拡張機能がエラーなくアクティブ化される
  • すべてのコマンドが登録され、動作する
  • パッケージサイズが5MB未満(.vscodeignore を使用)
  • README.md にマーケットプレイス/GitHub リンクが含まれている

クイックトラブルシューティング

症状修正方法
拡張機能が読み込まれないactivationEvents を確認(VS Code 1.74 以降、コマンド/ビューがコントリビュートされていれば自動検出)
コマンドが見つからないpackage.json とコード内のコマンドIDを一致させる
ショートカットが機能しないwhen 句を削除し、競合を確認

リファレンス

トピック参照先
AI カスタマイズreferences/ai-customization.md
コードレビュープロンプトreferences/code-review-prompts.md
コードサンプルreferences/code-samples.md
TreeViewreferences/treeview.md
Webviewreferences/webview.md
テストreferences/testing.md
公開references/publishing.md
トラブルシューティングreferences/troubleshooting.md

ベストプラクティス

命名の一貫性

公開前に、パッケージ名、設定キー、コマンドID、ビューIDを統一します:

項目例
パッケージ名copilot-scheduler
設定キーcopilotScheduler.enabled
コマンドIDcopilotScheduler.createTask
ビューIDcopilotSchedulerTasks

一元化された通知処理

type NotificationMode = "sound" | "silentToast" | "silentStatus";

function getNotificationMode(): NotificationMode {
  const config = vscode.workspace.getConfiguration("myExtension");
  return config.get<NotificationMode>("notificationMode", "sound");
}

function notifyInfo(message: string, timeoutMs = 4000): void {
  const mode = getNotificationMode();
  switch (mode) {
    case "silentStatus":
      vscode.window.setStatusBarMessage(message, timeoutMs);
      break;
    case "silentToast":
      void vscode.window.withProgress(
        { location: vscode.ProgressLocation.Notification, title: message },
        async () => {},
      );
      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);
}

ユーザーが通知の配信方法を制御できるように、notificationMode 設定を公開します。

関連スキル