-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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 EnvironmentVariableCollection API to apply changes via shell integration #179476
Comments
@Tyriar FYI none of the integration scripts work if |
Moving this to next milestone as this is a feature request and we are late in the release cycle to make this happen. |
Proposal: export enum EnvironmentVariableMutatorTiming {
/**
* Apply to the environment just before the process is created.
*/
ProcessCreation = 1,
/**
* Apply to the environment in the shell integration script. Note that this _will not_ apply
* the mutator if shell integration is disabled or not working for some reason.
*/
ShellIntegration = 2,
/**
* Apply to the environment just before the process is created and then again in the shell
* integration script. Note that this _will not_ apply the mutator if shell integration is
* disabled or not working for some reason.
*/
Both = 3
}
export interface EnvironmentVariableMutatorOptions {
/**
* When the mutator will be applied to the environment.
*/
timing?: EnvironmentVariableMutatorTiming;
}
/**
* A type of mutation and its value to be applied to an environment variable.
*/
export interface EnvironmentVariableMutator {
/**
* Options applied to the mutator.
*/
readonly options?: EnvironmentVariableMutatorOptions;
}
export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> {
/**
* @param options Options applied to the mutator.
*/
replace(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void;
/**
* @param options Options applied to the mutator.
*/
append(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void;
/**
* @param options Options applied to the mutator.
*/
prepend(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void;
} The |
Feedback from API sync:
|
I couldn't find many examples of similar things, and when I did it's optional everywhere like in vscode/src/vscode-dts/vscode.d.ts Lines 7538 to 7572 in a9d434a
I'll keep it as is for now as we can make it non-undefined later in a non-breaking change. |
Updated proposal after feedback: export interface EnvironmentVariableMutatorOptions {
/**
* Apply to the environment just before the process is created.
*
* Defaults to true.
*/
applyAtProcessCreation?: boolean;
/**
* Apply to the environment in the shell integration script. Note that this _will not_ apply
* the mutator if shell integration is disabled or not working for some reason.
*
* Defaults to false.
*/
applyAtShellIntegration?: boolean;
}
/**
* A type of mutation and its value to be applied to an environment variable.
*/
export interface EnvironmentVariableMutator {
/**
* Options applied to the mutator.
*/
readonly options: EnvironmentVariableMutatorOptions;
}
export interface EnvironmentVariableCollection extends Iterable<[variable: string, mutator: EnvironmentVariableMutator]> {
/**
* @param options Options applied to the mutator.
*/
replace(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void;
/**
* @param options Options applied to the mutator.
*/
append(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void;
/**
* @param options Options applied to the mutator.
*/
prepend(variable: string, value: string, options?: EnvironmentVariableMutatorOptions): void;
} Comments:
|
Currently blocked on the changes to workspace scope moving to a |
TPI #182970 |
Question for API sync: #182883 (review) |
Feedback to bring to sync:
|
Another option: Rename it to |
The bugs don't block this as they shouldn't change the API shape. |
We do need to finalize how the defaults work for |
Let's treat undefined as false and update the jsdoc to explain this. Good to finalize |
Particularly for Python extension, it's easy to miss to set or not set it when replacing or prepending: envVarCollection.replace(
'PATH',
`${path.dirname(interpreter.path)}${path.delimiter}${process.env[pathVarName]}`,
{ applyAtShellIntegration: true, applyAtProcessCreation: true },
); or envVarCollection.prepend('PS1', value, {
applyAtShellIntegration: true,
applyAtProcessCreation: false,
}); Maybe we should consider making it a required parameter as it is always something which we look at. |
@karrtikr the options arg can't be required due to backwards compatibility, the individual option properties should be required as then it would be inconsistent if we added a new property (which must be optional). I think the undefined is treated as false thing fixes most of the API ux problems. |
To be clear, I'm suggesting just to make applyAtProcessCreation required when using options. As that is the confusing property which changes value when options is used. |
A problem the Python extension has is that it sets environment variables but they get overridden during shell startup scripts. This issue would allow adding an option to the variable mutator for the timing a particular environment variable is applied.
The text was updated successfully, but these errors were encountered: