Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update proposed scoped environment collection API #190532

Merged
merged 5 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/vs/workbench/api/common/extHostExtensionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ export abstract class AbstractExtHostExtensionService extends Disposable impleme
return that.extensionRuntime;
},
get environmentVariableCollection() { return that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription); },
getEnvironmentVariableCollection(scope?: vscode.EnvironmentVariableScope) { return that._extHostTerminalService.getEnvironmentVariableCollection(extensionDescription, scope); },
get messagePassingProtocol() {
if (!messagePassingProtocol) {
if (!messagePort) {
Expand Down
17 changes: 11 additions & 6 deletions src/vs/workbench/api/common/extHostTerminalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ export interface IExtHostTerminalService extends ExtHostTerminalServiceShape, ID
registerLinkProvider(provider: vscode.TerminalLinkProvider): vscode.Disposable;
registerProfileProvider(extension: IExtensionDescription, id: string, provider: vscode.TerminalProfileProvider): vscode.Disposable;
registerTerminalQuickFixProvider(id: string, extensionId: string, provider: vscode.TerminalQuickFixProvider): vscode.Disposable;
getEnvironmentVariableCollection(extension: IExtensionDescription, scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection;
getEnvironmentVariableCollection(extension: IExtensionDescription): IEnvironmentVariableCollection;
}

interface IEnvironmentVariableCollection extends vscode.EnvironmentVariableCollection {
getScoped(scope: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection;
}

export interface ITerminalInternalOptions {
isFeatureTerminal?: boolean;
useShellEnvironment?: boolean;
Expand Down Expand Up @@ -850,13 +855,13 @@ export abstract class BaseExtHostTerminalService extends Disposable implements I
return index;
}

public getEnvironmentVariableCollection(extension: IExtensionDescription, scope?: vscode.EnvironmentVariableScope): vscode.EnvironmentVariableCollection {
public getEnvironmentVariableCollection(extension: IExtensionDescription): IEnvironmentVariableCollection {
let collection = this._environmentVariableCollections.get(extension.identifier.value);
if (!collection) {
collection = new UnifiedEnvironmentVariableCollection(extension);
this._setEnvironmentVariableCollection(extension.identifier.value, collection);
}
return collection.getScopedEnvironmentVariableCollection(scope);
return collection.getScopedEnvironmentVariableCollection(undefined);
}

private _syncEnvironmentVariableCollection(extensionIdentifier: string, collection: UnifiedEnvironmentVariableCollection): void {
Expand Down Expand Up @@ -923,7 +928,7 @@ class UnifiedEnvironmentVariableCollection {
this.map = new Map(serialized);
}

getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined): vscode.EnvironmentVariableCollection {
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');
Expand Down Expand Up @@ -1066,7 +1071,7 @@ class UnifiedEnvironmentVariableCollection {
}
}

class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableCollection {
class ScopedEnvironmentVariableCollection implements IEnvironmentVariableCollection {
public get persistent(): boolean { return this.collection.persistent; }
public set persistent(value: boolean) {
this.collection.persistent = value;
Expand All @@ -1081,7 +1086,7 @@ class ScopedEnvironmentVariableCollection implements vscode.EnvironmentVariableC
) {
}

getScopedEnvironmentVariableCollection(scope: vscode.EnvironmentVariableScope | undefined) {
getScoped(scope: vscode.EnvironmentVariableScope | undefined) {
return this.collection.getScopedEnvironmentVariableCollection(scope);
}

Expand Down
25 changes: 15 additions & 10 deletions src/vscode-dts/vscode.proposed.envCollectionWorkspace.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,30 @@ declare module 'vscode' {

export interface ExtensionContext {
/**
* Gets the extension's environment variable collection for this workspace, enabling changes
* to be applied to terminal environment variables.
*
* @deprecated Use {@link getEnvironmentVariableCollection} instead.
* 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;
}

interface GlobalEnvironmentVariableCollection extends EnvironmentVariableCollection {
/**
* Gets the extension's environment variable collection for this scope, enabling changes
* to be applied to terminal environment variables.
* 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.
*/
getEnvironmentVariableCollection(scope?: EnvironmentVariableScope): EnvironmentVariableCollection;
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.
*/
* Any specific workspace folder to get collection for. If unspecified, collection applicable to all workspace folders is returned.
karrtikr marked this conversation as resolved.
Show resolved Hide resolved
*/
workspaceFolder?: WorkspaceFolder;
};
}