How to understand a VS Code extension codebase
A VS Code extension declares what it adds in `package.json` under `contributes` and when to load under `activationEvents`. When it activates, `activate(context)` registers the implementations. Larger extensions split into a client and a language server, or use webviews for custom UI.
How to tell it's VS Code extension
- An
engines.vscodefield and acontributessection inpackage.json src/extension.tsexportingactivateanddeactivatevscode.commands.registerCommandandcontext.subscriptions.push(...)
Where things usually live
- package.json
- Commands, menus, keybindings, settings, views and activation events.
- src/extension.ts
activateregisters commands and providers.- src/commands/
- Command implementations.
- src/providers/
- Tree views, completion, hover and other providers.
- src/webview/ or media/
- Webview UI and its messaging.
- server/
- A language server process, if the extension has one.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
contributesinpackage.json, for what the user seesactivate, for what gets registered- The command ID you care about, searched across both
How a request moves through the code
- An activation event fires, such as a command run or a file type opened.
- VS Code calls
activate(context). - The extension registers commands and providers and adds them to
context.subscriptions. - The user triggers a command by its ID from the palette, a menu or a keybinding.
- The handler uses the
vscodeAPI, or posts messages to a webview or language server.
Questions to ask about the repository
- Map each command ID in
package.jsonto its handler. - What triggers activation?
- Which settings does the extension read, and where?
What trips people up
- A command declared in
contributesbut never registered shows in the palette and fails when run. - Disposables not added to
context.subscriptionsleak when the extension deactivates. - Webviews communicate only through
postMessage; their code runs in a separate sandbox.