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

Allow specifying workspace-specific EnvironmentVariableCollection mutators #171173

Closed
Tracked by #20822
Tyriar opened this issue Jan 12, 2023 · 20 comments · Fixed by #191016
Closed
Tracked by #20822

Allow specifying workspace-specific EnvironmentVariableCollection mutators #171173

Tyriar opened this issue Jan 12, 2023 · 20 comments · Fixed by #191016
Assignees
Labels
api api-finalization feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-testplan terminal-process Problems launching processes, managing ptys, exiting, process leaks, etc.
Milestone

Comments

@Tyriar
Copy link
Member

Tyriar commented Jan 12, 2023

For example:

export interface EnvironmentVariableMutator {
	readonly type: EnvironmentVariableMutatorType;
	readonly value: string;
	readonly workspace: Workspace | undefined;
}

export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> {
	replace(variable: string, value: string, workspace?: Workspace): void;
	append(variable: string, value: string, workspace?: Workspace): void;
	prepend(variable: string, value: string, workspace?: Workspace): void;
}

Context: microsoft/vscode-python#20492 (comment)

@Tyriar Tyriar added feature-request Request for new features or functionality api terminal-process Problems launching processes, managing ptys, exiting, process leaks, etc. labels Jan 12, 2023
@Tyriar Tyriar added this to the Backlog milestone Jan 12, 2023
@Tyriar Tyriar modified the milestones: Backlog, March 2023 Mar 7, 2023
@karrtikr karrtikr self-assigned this Mar 13, 2023
@Tyriar Tyriar modified the milestones: March 2023, April 2023 Mar 20, 2023
@karrtikr
Copy link
Contributor

karrtikr commented Apr 3, 2023

Feedback from API sync:

As we anticipate we might need shell scoping as well in the future, use something similar to

workspace.getConfiguration(section?: string, scope?: ConfigurationScope): WorkspaceConfiguration;

instead.

Updated proposal:

export interface EnvironmentVariableMutator {
	readonly type: EnvironmentVariableMutatorType;
	readonly value: string;
	readonly scope: EnvironmentVariableScope | undefined;
}

export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> {
	replace(variable: string, value: string, scope?: EnvironmentVariableScope): void;
	append(variable: string, value: string, scope?: EnvironmentVariableScope): void;
	prepend(variable: string, value: string, scope?: EnvironmentVariableScope): void;
}

export type EnvironmentVariableScope = {
    /**
     * The workspace folder to which this environment variable collection applies to.
     * If unspecified, the collection applies to all workspace folders.
     */
    workspaceFolder?: WorkspaceFolder;
};

One issue with this is that readonly scope: EnvironmentVariableScope | undefined; carries optional properties. Hence an alternative could be:

export interface EnvironmentVariableMutator {
	readonly type: EnvironmentVariableMutatorType;
	readonly value: string;
	readonly scope: Required<EnvironmentVariableScope> | undefined;
}

@Tyriar
Copy link
Member Author

Tyriar commented Apr 3, 2023

One issue with this is that readonly scope: EnvironmentVariableScope | undefined; carries optional properties. Hence an alternative could be:

The required would need to be removed when we added a second one anyway, we can just treat {} and { workspaceFolder: undefined } the same as undefined

@karrtikr
Copy link
Contributor

karrtikr commented Apr 3, 2023

Sorry what do you mean by the "second one"? Mostly I was trying to follow Extension-API-guidelines:

For readonly properties on interfaces that VS Code exposes to extensions: Use | undefined as this makes it clear the property exists but has the value undefined.

But I guess we don't have to strictly follow it?

@Tyriar
Copy link
Member Author

Tyriar commented Apr 3, 2023

@karrtikr by a second one I mean a second scope, we don't want the user to explicitly enumerate all the scopes to set it which Required<> would do.

@karrtikr
Copy link
Contributor

Updated proposal:

export interface EnvironmentVariableMutator {
	readonly type: EnvironmentVariableMutatorType;
	readonly value: string;
	readonly scope: EnvironmentVariableScope | undefined;
}

export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> {
	replace(variable: string, value: string, scope?: EnvironmentVariableScope): void;
	append(variable: string, value: string, scope?: EnvironmentVariableScope): void;
	prepend(variable: string, value: string, scope?: EnvironmentVariableScope): void;
	get(variable: string, scope?: EnvironmentVariableScope): EnvironmentVariableMutator | undefined;
	delete(variable: string, scope?: EnvironmentVariableScope): void;
	clear(scope?: EnvironmentVariableScope): void;
}

export type EnvironmentVariableScope = {
	/**
	* The workspace folder to which this collection applies to. If unspecified, collection applies to all workspace folders.
	*/
	workspaceFolder?: WorkspaceFolder;
};

Tyriar added a commit that referenced this issue Aug 8, 2023
@karrtikr
Copy link
Contributor

karrtikr commented Aug 8, 2023

Based on discussion in API sync, we should probably deprecate existing environmentVariableCollection API and merge it with the scoped one (similar to workspace.getConfiguration())

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.
	 */
	readonly environmentVariableCollection: EnvironmentVariableCollection;
	/**
	 * Gets the extension's environment variable collection for this workspace, enabling changes
	 * to be applied to terminal environment variables.
	 *
	 * @param scope The scope to which the environment variable collection applies to.
	 */
	getEnvironmentVariableCollection(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;
};

@Tyriar Tyriar self-assigned this Aug 8, 2023
@Tyriar
Copy link
Member Author

Tyriar commented Aug 8, 2023

Assigning myself too so it's easier for me to track 🙂

@karrtikr
Copy link
Contributor

@meganrogge @Tyriar When viewing contributions, is it possible to open the preview of the markdown directly instead of the .md file?

image

as opposed to

image

I can open preview using:

image

@Tyriar
Copy link
Member Author

Tyriar commented Aug 11, 2023

@karrtikr since this is an advanced feature I think the raw markdown is more flexible as the user can navigate and copy section of it better. So I don't think this is a necessary change personally

@Tyriar
Copy link
Member Author

Tyriar commented Aug 15, 2023

Feedback before finalization:

  • Add an interface GlobalEnviornmentVariableCollection implements EnvironmentVariableCollection
  • Add getScoped to the GlobalEnviornmentVariableCollection
  • Clarify how scoped interacts with the non-scoped collection
  • Don't deprecate

@karrtikr
Copy link
Contributor

karrtikr commented Aug 15, 2023

Updated proposal:

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;
}

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.
     */
    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;
};

@Tyriar
Copy link
Member Author

Tyriar commented Aug 15, 2023

Each object obtained through this method is isolated and does not impact objects for other scopes, including the global collection.

Should we also call out how it's applied in addition to (and after) the global collection?

Looks good otherwise 👍

@karrtikr
Copy link
Contributor

karrtikr commented Aug 15, 2023

Sure, I have modified the docstrings to append it

I plan to have the implementation ready but only merge and adopt it in Python extension next week to avoid multiple iterations.

@vscodenpa vscodenpa added the unreleased Patch has not yet been released in VS Code Insiders label Aug 23, 2023
karrtikr pushed a commit to microsoft/vscode-python that referenced this issue Aug 23, 2023
@vscodenpa vscodenpa added insiders-released Patch has been released in VS Code Insiders and removed unreleased Patch has not yet been released in VS Code Insiders labels Aug 24, 2023
anthonykim1 pushed a commit to anthonykim1/vscode-python that referenced this issue Sep 12, 2023
anthonykim1 pushed a commit to anthonykim1/vscode-python that referenced this issue Sep 12, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Oct 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api api-finalization feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-testplan terminal-process Problems launching processes, managing ptys, exiting, process leaks, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants