@@ -109,39 +109,33 @@ export function substituteVariables(str: string, recursive = false): string {
109109 return str ;
110110}
111111
112- /*
113- Environment setting helper functions
114- */
115-
116- export function getCustomEnv ( ) {
117- const env_config_name = getCustomEnvSettingName ( ) ;
112+ /**
113+ * Name of the `terminal.integrated.env.*` setting applicable to the current platform.
114+ */
115+ export const TERMINAL_ENV_SETTING_NAME =
116+ 'terminal.integrated.env.' +
117+ ( platform ( ) == 'darwin' ? 'osx' : platform ( ) == 'win32' ? 'windows' : 'linux' ) ;
118118
119+ /**
120+ *
121+ * @returns the value of the applicable `terminal.integrated.env.*` setting,
122+ * without evaluation of macros such as `${env:...}`.
123+ */
124+ export function getTerminalEnv ( ) {
119125 const custom_env = vscode . workspace
120126 . getConfiguration ( )
121- . get < { [ name : string ] : string } > ( env_config_name ) ;
127+ . get < { [ name : string ] : string } > ( TERMINAL_ENV_SETTING_NAME ) ;
122128
123129 return custom_env ;
124130}
125131
126- export function getCustomEnvSettingName ( ) {
127- const user_platform = platform ( ) ;
128- let env_config_name = 'terminal.integrated.env' ;
129-
130- switch ( user_platform ) {
131- case 'darwin' :
132- env_config_name += '.osx' ;
133- break ;
134- case 'win32' :
135- env_config_name += '.windows' ;
136- break ;
137- default :
138- env_config_name += '.linux' ;
139- }
140- return env_config_name ;
141- }
142-
143- export function getEvaluatedCustomEnv ( ) {
144- const custom_env = getCustomEnv ( ) ;
132+ /**
133+ *
134+ * @returns the value of the applicable `terminal.integrated.env.*` setting,
135+ * after evaluation of macros such as `${env:...}`.
136+ */
137+ export function getEvaluatedTerminalEnv ( ) {
138+ const custom_env = getTerminalEnv ( ) ;
145139
146140 if ( custom_env ) {
147141 for ( const var_name in custom_env ) {
@@ -160,17 +154,13 @@ export function getEvaluatedCustomEnv() {
160154 * Read the environment variables specified in the vscode setting
161155 * `terminal.integrated.env.<os>` and set them in the given ProcessEnv object.
162156 *
163- * If no targetEnv is given, `process.env` is used as a target environment.
157+ * The targetEnv can be `process.env` to apply the changes to the environment of
158+ * the running process.
164159 */
165- export function setCustomEnvironment ( targetEnv ?: NodeJS . ProcessEnv ) {
166- if ( ! targetEnv ) {
167- targetEnv = process . env ;
168- }
169-
160+ export function setTerminalEnvironment ( targetEnv : NodeJS . ProcessEnv ) {
170161 // Retrieve the user's custom environment variables if specified in their
171- // settings/workspace: we'll then launch any child process with this custom
172- // environment
173- const custom_env = getEvaluatedCustomEnv ( ) ;
162+ // settings/workspace
163+ const custom_env = getEvaluatedTerminalEnv ( ) ;
174164
175165 if ( custom_env ) {
176166 for ( const var_name in custom_env ) {
@@ -183,7 +173,7 @@ export function setCustomEnvironment(targetEnv?: NodeJS.ProcessEnv) {
183173export function assertSupportedEnvironments ( mainChannel : winston . Logger ) {
184174 // Get the ALS environment variable from the custom environment, or from the
185175 // process environment
186- const customEnv = getEvaluatedCustomEnv ( ) ;
176+ const customEnv = getEvaluatedTerminalEnv ( ) ;
187177 const als = customEnv ?. ALS ?? process . env . ALS ;
188178 if ( als ) {
189179 // The User provided an external ALS executable. Do not perform any
0 commit comments