The Extension Host is a dedicated execution environment designed to run VS Code extensions in isolation from the main workbench UI. This multi-process architecture ensures that computationally expensive extension operations (like heavy language analysis or file system indexing) do not block the UI thread, maintaining a responsive editor experience.
The AbstractExtensionService in src/vs/workbench/services/extensions/common/abstractExtensionService.ts60 is the core orchestrator for managing extension lifecycles. It coordinates scanning, activation, and communication with various extension host types.
VS Code supports three primary extension host environments, determined by the ExtensionHostKind src/vs/workbench/services/extensions/common/extensionHostKind.ts10-14:
| Type | Class | Implementation Detail |
|---|---|---|
| Local Process | NativeLocalProcessExtensionHost | A separate Node.js process spawned via Electron's utility process. src/vs/workbench/services/extensions/electron-browser/localProcessExtensionHost.ts96 |
| Web Worker | WebWorkerExtensionHost | Runs in a browser Web Worker inside a sandboxed iframe. src/vs/workbench/services/extensions/browser/webWorkerExtensionHost.ts47 |
| Remote | RemoteExtensionHost | Runs on a remote machine via the Remote Extension Host (REH) agent. src/vs/workbench/services/extensions/common/remoteExtensionHost.ts47 |
The service uses a LockableExtensionDescriptionRegistry src/vs/workbench/services/extensions/common/abstractExtensionService.ts86 to manage the set of known extensions. Activation is triggered by events (e.g., onLanguage:python, onCommand:abc) managed by the ExtensionsActivator src/vs/workbench/api/common/extHostExtensionActivator.ts241
Scanning is handled by platform-specific implementations. For instance, ExtensionService in the browser calls _scanWebExtensions src/vs/workbench/services/extensions/browser/extensionService.ts75 via the IWebExtensionsScannerService.
Sources: src/vs/workbench/services/extensions/common/abstractExtensionService.ts60-105 src/vs/workbench/services/extensions/electron-browser/localProcessExtensionHost.ts96-103 src/vs/workbench/services/extensions/browser/webWorkerExtensionHost.ts47-54 src/vs/workbench/services/extensions/common/extensionHostKind.ts10-14 src/vs/workbench/services/extensions/browser/extensionService.ts46-105
Communication between the Main Thread (Workbench) and the Extension Host occurs over an asynchronous RPC protocol.
The boundary is crossed using ProxyIdentifier src/vs/workbench/services/extensions/common/proxyIdentifier.ts31 These identifiers map a service interface to a concrete implementation on the opposite side of the process boundary.
MainThreadLanguageFeatures). src/vs/workbench/api/common/extHost.protocol.ts577ExtHostLanguageFeatures). src/vs/workbench/api/common/extHost.protocol.ts517Sources: src/vs/workbench/api/common/extHost.protocol.ts517-600 src/vs/workbench/services/extensions/common/proxyIdentifier.ts31-40 src/vs/workbench/services/extensions/common/rpcProtocol.ts54
AbstractExtHostExtensionService src/vs/workbench/api/common/extHostExtensionService.ts81 is the entry point within the Extension Host. It initializes the environment for extensions and manages their execution.
IExtensionHostInitData src/vs/workbench/services/extensions/common/extensionHostProtocol.ts28-60 containing workspace info, configuration, and extension descriptions.vscode API object via createApiFactoryAndRegisterActors. This factory populates the vscode namespace with classes like Position, Range, and CancellationTokenSource.ActivatedExtension class wrapper src/vs/workbench/api/common/extHostExtensionActivator.ts59Sources: src/vs/workbench/api/common/extHostExtensionService.ts81-150 src/vs/workbench/services/extensions/common/extensionHostProtocol.ts28-60 src/vs/workbench/api/common/extHostExtensionActivator.ts59-90
The ExtensionHostManager src/vs/workbench/services/extensions/common/extensionHostManager.ts58 acts as a supervisor on the workbench side. It handles the low-level details of process spawning and connection establishment.
For local processes, it utilizes the IExtensionHostProxy src/vs/workbench/services/extensions/common/extensionHostProxy.ts16 which communicates with the actual extension host implementation. It monitors the onExit event src/vs/workbench/services/extensions/common/extensionHostManager.ts108 to handle crashes or graceful shutdowns.
Sources: src/vs/workbench/services/extensions/common/extensionHostManager.ts58-130 src/vs/workbench/api/common/extHostExtensionService.ts81-150 src/vs/workbench/services/extensions/common/extensionHostProxy.ts16-40
Because the RPC boundary only supports JSON-serializable data, VS Code uses a strict Data Transfer Object (DTO) pattern.
vscode API types.Sources: src/vs/workbench/api/common/extHostExtensionService.ts81-120 src/vs/workbench/services/extensions/common/proxyIdentifier.ts31-69 src/vs/workbench/services/extensions/common/extensionHostProtocol.ts19-26
Sources:
Refresh this wiki
This wiki was recently refreshed. Please wait 7 days to refresh again.