An extension context is a collection of utilities private to an extension.

An instance of an ExtensionContext is provided as the first parameter to the activate-call of an extension.

Fields

read onlyworkspaceState:Memento

A memento object that stores state in the context of the currently opened {@link workspace.workspaceFolders workspace}.

read onlysubscriptions:Array<{dispose:() ‑> Void}>

An array to which disposables can be added. When this extension is deactivated the disposables will be disposed.

read onlystorageUri:Null<Uri>

The uri of a workspace specific directory in which the extension can store private state. The directory might not exist and creation is up to the extension. However, the parent directory is guaranteed to be existent. The value is undefined when no workspace nor folder has been opened.

Use {@linkcode ExtensionContext.workspaceState workspaceState} or {@linkcode ExtensionContext.globalState globalState} to store key value data.

@linkcode FileSystem workspace.fs} for how to read and write files and folders from an uri.

See also:

  • {

read onlystoragePath:Null<String>

Deprecated: "Use `ExtensionContext.storageUri` instead."
Deprecated:

Use {

An absolute file path of a workspace specific directory in which the extension can store private state. The directory might not exist on disk and creation is up to the extension. However, the parent directory is guaranteed to be existent.

Use {@linkcode ExtensionContext.workspaceState workspaceState} or {@linkcode ExtensionContext.globalState globalState} to store key value data.

@link ExtensionContext.storageUri storageUri} instead.

read onlysecrets:SecretStorage

A storage utility for secrets. Secrets are persisted across reloads and are independent of the current opened {@link workspace.workspaceFolders workspace}.

read onlylogUri:Uri

The uri of a directory in which the extension can create log files. The directory might not exist on disk and creation is up to the extension. However, the parent directory is guaranteed to be existent.

@linkcode FileSystem workspace.fs} for how to read and write files and folders from an uri.

See also:

  • {

read onlylogPath:String

Deprecated: "Use `ExtensionContext.logUri` instead."
Deprecated:

Use {

An absolute file path of a directory in which the extension can create log files. The directory might not exist on disk and creation is up to the extension. However, the parent directory is guaranteed to be existent.

@link ExtensionContext.logUri logUri} instead.

read onlyglobalStorageUri:Uri

The uri of a directory in which the extension can store global state. The directory might not exist on disk and creation is up to the extension. However, the parent directory is guaranteed to be existent.

Use {@linkcode ExtensionContext.globalState globalState} to store key value data.

@linkcode FileSystem workspace.fs} for how to read and write files and folders from an uri.

See also:

  • {

read onlyglobalStoragePath:String

Deprecated: "Use `ExtensionContext.globalStorageUri` instead."
Deprecated:

Use {

An absolute file path in which the extension can store global state. The directory might not exist on disk and creation is up to the extension. However, the parent directory is guaranteed to be existent.

Use {@linkcode ExtensionContext.globalState globalState} to store key value data.

@link ExtensionContext.globalStorageUri globalStorageUri} instead.

read onlyglobalState:{update:(key:String, value:Any) ‑> Thenable<Void>, setKeysForSync:(keys:ReadOnlyArray<String>) ‑> Void, keys:() ‑> ReadOnlyArray<String>, get:(key:String) ‑> Null<T>}

A memento object that stores state independent of the current opened {@link workspace.workspaceFolders workspace}.

read onlyextensionUri:String

The uri of the directory containing the extension.

read onlyextensionPath:String

The absolute file path of the directory containing the extension. Shorthand notation for {@link TextDocument.uri ExtensionContext.extensionUri.fsPath} (independent of the uri scheme).

read onlyextensionMode:ExtensionMode

The mode the extension is running in. This is specific to the current extension. One extension may be in ExtensionMode.Development while other extensions in the host run in ExtensionMode.Release.

read onlyextension:Extension<Dynamic>

The current Extension instance.

read onlyenvironmentVariableCollection:EnvironmentVariableCollection

Gets the extension's environment variable collection for this workspace, enabling changes to be applied to terminal environment variables.

asAbsolutePath(relativePath:String):String

Get the absolute path of a resource contained in the extension.

Note that an absolute uri can be constructed via {@linkcode Uri.joinPath} and {@linkcode ExtensionContext.extensionUri extensionUri}, e.g. vscode.Uri.joinPath(context.extensionUri, relativePath);

Parameters:

relativePath

A relative path to a resource contained in the extension.

Returns:

The absolute path of the resource.