33
44import  *  as  path  from  'path' ; 
55import  {  inject ,  injectable  }  from  'inversify' ; 
6- import  { 
7-  ProgressOptions , 
8-  ProgressLocation , 
9-  MarkdownString , 
10-  WorkspaceFolder , 
11-  EnvironmentVariableCollection , 
12-  EnvironmentVariableScope , 
13- }  from  'vscode' ; 
6+ import  {  ProgressOptions ,  ProgressLocation ,  MarkdownString ,  WorkspaceFolder  }  from  'vscode' ; 
147import  {  pathExists  }  from  'fs-extra' ; 
158import  {  IExtensionActivationService  }  from  '../../activation/types' ; 
169import  {  IApplicationShell ,  IApplicationEnvironment ,  IWorkspaceService  }  from  '../../common/application/types' ; 
@@ -67,7 +60,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
6760
6861 public  async  activate ( resource : Resource ) : Promise < void >  { 
6962 if  ( ! inTerminalEnvVarExperiment ( this . experimentService ) )  { 
70-  this . context . environmentVariableCollection . clear ( ) ; 
63+  const  workspaceFolder  =  this . getWorkspaceFolder ( resource ) ; 
64+  this . context . getEnvironmentVariableCollection ( {  workspaceFolder } ) . clear ( ) ; 
7165 await  this . handleMicroVenv ( resource ) ; 
7266 if  ( ! this . registeredOnce )  { 
7367 this . interpreterService . onDidChangeInterpreter ( 
@@ -111,8 +105,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
111105 public  async  _applyCollection ( resource : Resource ,  shell  =  this . applicationEnvironment . shell ) : Promise < void >  { 
112106 const  workspaceFolder  =  this . getWorkspaceFolder ( resource ) ; 
113107 const  settings  =  this . configurationService . getSettings ( resource ) ; 
114-  const  envVarCollection  =  this . getEnvironmentVariableCollection ( workspaceFolder ) ; 
115-  // Clear any previously set env vars from collection.  
108+  const  envVarCollection  =  this . context . getEnvironmentVariableCollection ( {   workspaceFolder  } ) ; 
109+  // Clear any previously set env vars from collection 
116110 envVarCollection . clear ( ) ; 
117111 if  ( ! settings . terminal . activateEnvironment )  { 
118112 traceVerbose ( 'Activating environments in terminal is disabled for' ,  resource ?. fsPath ) ; 
@@ -160,7 +154,10 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
160154 return ; 
161155 } 
162156 traceVerbose ( `Setting environment variable ${ key } ${ value }  ) ; 
163-  envVarCollection . replace ( key ,  value ,  {  applyAtShellIntegration : true  } ) ; 
157+  envVarCollection . replace ( key ,  value ,  { 
158+  applyAtShellIntegration : true , 
159+  applyAtProcessCreation : true , 
160+  } ) ; 
164161 } 
165162 } 
166163 } ) ; 
@@ -170,22 +167,13 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
170167 envVarCollection . description  =  description ; 
171168 } 
172169
173-  private  getEnvironmentVariableCollection ( workspaceFolder ?: WorkspaceFolder )  { 
174-  const  envVarCollection  =  this . context . environmentVariableCollection  as  EnvironmentVariableCollection  &  { 
175-  getScopedEnvironmentVariableCollection ( scope : EnvironmentVariableScope ) : EnvironmentVariableCollection ; 
176-  } ; 
177-  return  workspaceFolder 
178-  ? envVarCollection . getScopedEnvironmentVariableCollection ( {  workspaceFolder } ) 
179-  : envVarCollection ; 
180-  } 
181- 
182170 private  async  handleMicroVenv ( resource : Resource )  { 
183171 const  workspaceFolder  =  this . getWorkspaceFolder ( resource ) ; 
184172 const  interpreter  =  await  this . interpreterService . getActiveInterpreter ( resource ) ; 
185173 if  ( interpreter ?. envType  ===  EnvironmentType . Venv )  { 
186174 const  activatePath  =  path . join ( path . dirname ( interpreter . path ) ,  'activate' ) ; 
187175 if  ( ! ( await  pathExists ( activatePath ) ) )  { 
188-  const  envVarCollection  =  this . getEnvironmentVariableCollection ( workspaceFolder ) ; 
176+  const  envVarCollection  =  this . context . getEnvironmentVariableCollection ( {   workspaceFolder  } ) ; 
189177 const  pathVarName  =  getSearchPathEnvVarNames ( ) [ 0 ] ; 
190178 envVarCollection . replace ( 
191179 'PATH' , 
@@ -195,7 +183,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
195183 return ; 
196184 } 
197185 } 
198-  this . context . environmentVariableCollection . clear ( ) ; 
186+  this . context . getEnvironmentVariableCollection ( {  workspaceFolder  } ) . clear ( ) ; 
199187 } 
200188
201189 private  getWorkspaceFolder ( resource : Resource ) : WorkspaceFolder  |  undefined  { 
0 commit comments