3
3
4
4
import * as path from 'path' ;
5
5
import { 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' ;
14
7
import { pathExists } from 'fs-extra' ;
15
8
import { IExtensionActivationService } from '../../activation/types' ;
16
9
import { IApplicationShell , IApplicationEnvironment , IWorkspaceService } from '../../common/application/types' ;
@@ -67,7 +60,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
67
60
68
61
public async activate ( resource : Resource ) : Promise < void > {
69
62
if ( ! inTerminalEnvVarExperiment ( this . experimentService ) ) {
70
- this . context . environmentVariableCollection . clear ( ) ;
63
+ const workspaceFolder = this . getWorkspaceFolder ( resource ) ;
64
+ this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) . clear ( ) ;
71
65
await this . handleMicroVenv ( resource ) ;
72
66
if ( ! this . registeredOnce ) {
73
67
this . interpreterService . onDidChangeInterpreter (
@@ -111,8 +105,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
111
105
public async _applyCollection ( resource : Resource , shell = this . applicationEnvironment . shell ) : Promise < void > {
112
106
const workspaceFolder = this . getWorkspaceFolder ( resource ) ;
113
107
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
116
110
envVarCollection . clear ( ) ;
117
111
if ( ! settings . terminal . activateEnvironment ) {
118
112
traceVerbose ( 'Activating environments in terminal is disabled for' , resource ?. fsPath ) ;
@@ -160,7 +154,10 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
160
154
return ;
161
155
}
162
156
traceVerbose ( `Setting environment variable ${ key } in collection to ${ value } ` ) ;
163
- envVarCollection . replace ( key , value , { applyAtShellIntegration : true } ) ;
157
+ envVarCollection . replace ( key , value , {
158
+ applyAtShellIntegration : true ,
159
+ applyAtProcessCreation : true ,
160
+ } ) ;
164
161
}
165
162
}
166
163
} ) ;
@@ -170,22 +167,13 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
170
167
envVarCollection . description = description ;
171
168
}
172
169
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
-
182
170
private async handleMicroVenv ( resource : Resource ) {
183
171
const workspaceFolder = this . getWorkspaceFolder ( resource ) ;
184
172
const interpreter = await this . interpreterService . getActiveInterpreter ( resource ) ;
185
173
if ( interpreter ?. envType === EnvironmentType . Venv ) {
186
174
const activatePath = path . join ( path . dirname ( interpreter . path ) , 'activate' ) ;
187
175
if ( ! ( await pathExists ( activatePath ) ) ) {
188
- const envVarCollection = this . getEnvironmentVariableCollection ( workspaceFolder ) ;
176
+ const envVarCollection = this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) ;
189
177
const pathVarName = getSearchPathEnvVarNames ( ) [ 0 ] ;
190
178
envVarCollection . replace (
191
179
'PATH' ,
@@ -195,7 +183,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
195
183
return ;
196
184
}
197
185
}
198
- this . context . environmentVariableCollection . clear ( ) ;
186
+ this . context . getEnvironmentVariableCollection ( { workspaceFolder } ) . clear ( ) ;
199
187
}
200
188
201
189
private getWorkspaceFolder ( resource : Resource ) : WorkspaceFolder | undefined {
0 commit comments