Finalize proposed env workspace collection API

This commit is contained in:
Kartik Raj 2023-08-22 20:22:32 +00:00
parent f40dabca07
commit b1d5542cfd
6 changed files with 30 additions and 54 deletions

View file

@ -51,7 +51,6 @@
"telemetry",
"windowActivity",
"interactiveUserActions",
"envCollectionWorkspace",
"envCollectionOptions"
],
"private": true,

View file

@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import { deepStrictEqual, doesNotThrow, equal, ok, strictEqual, throws } from 'assert';
import { commands, ConfigurationTarget, Disposable, env, EnvironmentVariableMutator, EnvironmentVariableMutatorOptions, EnvironmentVariableMutatorType, EventEmitter, ExtensionContext, extensions, ExtensionTerminalOptions, GlobalEnvironmentVariableCollection, Pseudoterminal, Terminal, TerminalDimensions, TerminalExitReason, TerminalOptions, TerminalState, UIKind, Uri, window, workspace } from 'vscode';
import { commands, ConfigurationTarget, Disposable, env, EnvironmentVariableMutator, EnvironmentVariableMutatorOptions, EnvironmentVariableMutatorType, EventEmitter, ExtensionContext, extensions, ExtensionTerminalOptions, Pseudoterminal, Terminal, TerminalDimensions, TerminalExitReason, TerminalOptions, TerminalState, UIKind, Uri, window, workspace } from 'vscode';
import { assertNoRpc, poll } from '../utils';
// Disable terminal tests:
@ -912,8 +912,7 @@ import { assertNoRpc, poll } from '../utils';
});
test('get and forEach should work (scope)', () => {
// TODO: Remove cast once `envCollectionWorkspace` API is finalized.
const collection = extensionContext.environmentVariableCollection as GlobalEnvironmentVariableCollection;
const collection = extensionContext.environmentVariableCollection;
disposables.push({ dispose: () => collection.clear() });
const scope = { workspaceFolder: { uri: Uri.file('workspace1'), name: 'workspace1', index: 0 } };
const scopedCollection = collection.getScoped(scope);

View file

@ -929,10 +929,6 @@ class UnifiedEnvironmentVariableCollection {
}
getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): IEnvironmentVariableCollection {
if (this._extension && scope) {
// TODO: This should be removed when the env var extension API(s) are stabilized
checkProposedApiEnabled(this._extension, 'envCollectionWorkspace');
}
const scopedCollectionKey = this.getScopeKey(scope);
let scopedCollection = this.scopedCollections.get(scopedCollectionKey);
if (!scopedCollection) {

View file

@ -41,7 +41,6 @@ export const allApiProposals = Object.freeze({
editSessionIdentityProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.editSessionIdentityProvider.d.ts',
editorInsets: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.editorInsets.d.ts',
envCollectionOptions: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.envCollectionOptions.d.ts',
envCollectionWorkspace: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts',
envShellEvent: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.envShellEvent.d.ts',
extensionRuntime: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.extensionRuntime.d.ts',
extensionsAny: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.extensionsAny.d.ts',

View file

@ -7185,10 +7185,10 @@ declare module 'vscode' {
readonly extensionPath: string;
/**
* Gets the extension's environment variable collection for this workspace, enabling changes
* to be applied to terminal environment variables.
* Gets the extension's global environment variable collection for this workspace, enabling changes to be
* applied to terminal environment variables.
*/
readonly environmentVariableCollection: EnvironmentVariableCollection;
readonly environmentVariableCollection: GlobalEnvironmentVariableCollection;
/**
* Get the absolute path of a resource contained in the extension.
@ -11429,6 +11429,31 @@ declare module 'vscode' {
clear(): void;
}
export interface GlobalEnvironmentVariableCollection extends EnvironmentVariableCollection {
/**
* Gets scope-specific environment variable collection for the extension. This enables alterations to
* terminal environment variables solely within the designated scope, and is applied in addition to (and
* after) the global collection.
*
* Each object obtained through this method is isolated and does not impact objects for other scopes,
* including the global collection.
*
* @param scope The scope to which the environment variable collection applies to.
*
* If a scope parameter is omitted, collection applicable to all relevant scopes for that parameter is
* returned. For instance, if the 'workspaceFolder' parameter is not specified, the collection that applies
* across all workspace folders will be returned.
*/
getScoped(scope: EnvironmentVariableScope): EnvironmentVariableCollection;
}
export type EnvironmentVariableScope = {
/**
* Any specific workspace folder to get collection for. If unspecified, collection applicable to all workspace folders is returned.
*/
workspaceFolder?: WorkspaceFolder;
};
/**
* A location in the editor at which progress information can be shown. It depends on the
* location how progress is visually represented.

View file

@ -1,42 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
declare module 'vscode' {
// https://github.com/microsoft/vscode/issues/171173
// export interface ExtensionContext {
// /**
// * Gets the extension's global environment variable collection for this workspace, enabling changes to be
// * applied to terminal environment variables.
// */
// readonly environmentVariableCollection: GlobalEnvironmentVariableCollection;
// }
export interface GlobalEnvironmentVariableCollection extends EnvironmentVariableCollection {
/**
* Gets scope-specific environment variable collection for the extension. This enables alterations to
* terminal environment variables solely within the designated scope, and is applied in addition to (and
* after) the global collection.
*
* Each object obtained through this method is isolated and does not impact objects for other scopes,
* including the global collection.
*
* @param scope The scope to which the environment variable collection applies to.
*
* If a scope parameter is omitted, collection applicable to all relevant scopes for that parameter is
* returned. For instance, if the 'workspaceFolder' parameter is not specified, the collection that applies
* across all workspace folders will be returned.
*/
getScoped(scope: EnvironmentVariableScope): EnvironmentVariableCollection;
}
export type EnvironmentVariableScope = {
/**
* Any specific workspace folder to get collection for. If unspecified, collection applicable to all workspace folders is returned.
*/
workspaceFolder?: WorkspaceFolder;
};
}