@@ -10,6 +10,7 @@ import {
10
10
EnvironmentVariableScope ,
11
11
EnvironmentVariableMutatorOptions ,
12
12
ProgressLocation ,
13
+ EnvironmentVariableCollection ,
13
14
} from 'vscode' ;
14
15
import { pathExists , normCase } from '../../common/platform/fs-paths' ;
15
16
import { IExtensionActivationService } from '../../activation/types' ;
@@ -37,7 +38,11 @@ import { TerminalShellType } from '../../common/terminal/types';
37
38
import { OSType } from '../../common/utils/platform' ;
38
39
39
40
import { PythonEnvType } from '../../pythonEnvironments/base/info' ;
40
- import { IShellIntegrationService , ITerminalDeactivateService , ITerminalEnvVarCollectionService } from '../types' ;
41
+ import {
42
+ IShellIntegrationDetectionService ,
43
+ ITerminalDeactivateService ,
44
+ ITerminalEnvVarCollectionService ,
45
+ } from '../types' ;
41
46
import { ProgressService } from '../../common/application/progressService' ;
42
47
43
48
@injectable ( )
@@ -80,7 +85,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
80
85
@inject ( IConfigurationService ) private readonly configurationService : IConfigurationService ,
81
86
@inject ( ITerminalDeactivateService ) private readonly terminalDeactivateService : ITerminalDeactivateService ,
82
87
@inject ( IPathUtils ) private readonly pathUtils : IPathUtils ,
83
- @inject ( IShellIntegrationService ) private readonly shellIntegrationService : IShellIntegrationService ,
88
+ @inject ( IShellIntegrationDetectionService )
89
+ private readonly shellIntegrationService : IShellIntegrationDetectionService ,
84
90
@inject ( IEnvironmentVariablesProvider )
85
91
private readonly environmentVariablesProvider : IEnvironmentVariablesProvider ,
86
92
) {
@@ -91,7 +97,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
91
97
public async activate ( resource : Resource ) : Promise < void > {
92
98
try {
93
99
if ( ! inTerminalEnvVarExperiment ( this . experimentService ) ) {
94
- this . context . environmentVariableCollection . clear ( ) ;
100
+ clearCollectionVariables ( this . context . environmentVariableCollection ) ;
101
+
95
102
await this . handleMicroVenv ( resource ) ;
96
103
if ( ! this . registeredOnce ) {
97
104
this . interpreterService . onDidChangeInterpreter (
@@ -171,7 +178,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
171
178
const settings = this . configurationService . getSettings ( resource ) ;
172
179
const envVarCollection = this . getEnvironmentVariableCollection ( { workspaceFolder } ) ;
173
180
if ( ! settings . terminal . activateEnvironment ) {
174
- envVarCollection . clear ( ) ;
181
+ clearCollectionVariables ( envVarCollection ) ;
175
182
traceVerbose ( 'Activating environments in terminal is disabled for' , resource ?. fsPath ) ;
176
183
return ;
177
184
}
@@ -193,7 +200,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
193
200
return ;
194
201
}
195
202
await this . trackTerminalPrompt ( shell , resource , env ) ;
196
- envVarCollection . clear ( ) ;
203
+ clearCollectionVariables ( envVarCollection ) ;
197
204
this . processEnvVars = undefined ;
198
205
return ;
199
206
}
@@ -210,7 +217,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
210
217
const defaultPrependOptions = await this . getPrependOptions ( ) ;
211
218
212
219
// Clear any previously set env vars from collection
213
- envVarCollection . clear ( ) ;
220
+ clearCollectionVariables ( envVarCollection ) ;
214
221
const deactivate = await this . terminalDeactivateService . getScriptLocation ( shell , resource ) ;
215
222
Object . keys ( env ) . forEach ( ( key ) => {
216
223
if ( shouldSkip ( key ) ) {
@@ -367,7 +374,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
367
374
const settings = this . configurationService . getSettings ( resource ) ;
368
375
const workspaceFolder = this . getWorkspaceFolder ( resource ) ;
369
376
if ( ! settings . terminal . activateEnvironment ) {
370
- this . getEnvironmentVariableCollection ( { workspaceFolder } ) . clear ( ) ;
377
+ clearCollectionVariables ( this . getEnvironmentVariableCollection ( { workspaceFolder } ) ) ;
371
378
traceVerbose (
372
379
'Do not activate microvenv as activating environments in terminal is disabled for' ,
373
380
resource ?. fsPath ,
@@ -387,7 +394,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
387
394
) ;
388
395
return ;
389
396
}
390
- this . getEnvironmentVariableCollection ( { workspaceFolder } ) . clear ( ) ;
397
+ clearCollectionVariables ( this . getEnvironmentVariableCollection ( { workspaceFolder } ) ) ;
391
398
}
392
399
} catch ( ex ) {
393
400
traceWarn ( `Microvenv failed as it is using proposed API which is constantly changing` , ex ) ;
@@ -485,3 +492,9 @@ function normCaseKeys(env: EnvironmentVariables): EnvironmentVariables {
485
492
} ) ;
486
493
return result ;
487
494
}
495
+
496
+ function clearCollectionVariables ( collection : EnvironmentVariableCollection ) {
497
+ for ( const key of [ 'PS1' , 'PATH' ] ) {
498
+ collection . delete ( key ) ;
499
+ }
500
+ }
0 commit comments