api.context
Interface: IContextApi
Implementation tier: T1
Read and write when-context keys used for conditional UI (when-clauses). Extensions can only write keys under their own namespace.
Methods
get
get(key: string): Promise<WhenContextValue | undefined>
Read a context key (built-in or extension-namespaced).
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
key | string | Yes |
Returns: Promise<WhenContextValue | undefined>
set
set(key: string, value: WhenContextValue): Promise<void>
Set an extension-namespaced context key. Throws on attempts to set
built-in keys (only ext.<id>.* keys are writable from extensions).
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
key | string | Yes | |
value | WhenContextValue | Yes |
Returns: Promise<void>
Events
onDidChange
onDidChange: IEventApi<{ keys: string[] }>
Payload type: { keys: string[] }
Subscribe to this event:
const handle = await api.context.onDidChange.subscribe((payload) => {
// Handle event
});
// Later, to unsubscribe:
await handle.dispose();