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

Test: EnvironmentVariableMutatorOptions API proposal #182970

Closed
3 tasks done
Tyriar opened this issue May 19, 2023 · 0 comments
Closed
3 tasks done

Test: EnvironmentVariableMutatorOptions API proposal #182970

Tyriar opened this issue May 19, 2023 · 0 comments

Comments

@Tyriar
Copy link
Member

Tyriar commented May 19, 2023

Refs: #179476

Complexity: 4

Create Issue


The EnvironmentVariableCollection allows extensions to change the terminal's process environment which enables features like the js-debug auto attach and git's authentication being handled VS Code. It's getting a new API proposal that allows specifying exactly when the variable "mutators" are applied.

Previously they would always be applied as the process is being created but now they can optionally be applied in the shell integration script as well which is done after shell initialization scripts are run. The specific problem this helps us solve is when setting the environment is critically important, such as environment activation in the Python extension, we can ensure that environment variables being touched in shell init scripts doesn't negatively impact the feature (when shell integration is enabled).

Current proposal:

declare module 'vscode' {

	// https://github.com/microsoft/vscode/issues/179476

	/**
	 * Options applied to the mutator.
	 */
	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;
	}
}

Test the following:

  • The API docs make sense
  • replace, append and prepend all apply the variable as expected
  • Test with and without options - to tell the difference between applyAtShellIntegration, try changing variables in your shell startup script, that should happen after applyAtProcessCreation and before applyAtShellIntegration
  • Test all combinations of applyAtProcessCreation and applyAtShellIntegration.
  • When applyAtProcessCreation is false and applyAtShellIntegration is false or undefined it should throw.
  • applyAtShellIntegration should not apply when shell integration is disabled (terminal.integrated.shellIntegration.enabled)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants