@@ -37,8 +37,7 @@ import { TerminalShellType } from '../../common/terminal/types';
37
37
import { OSType } from '../../common/utils/platform' ;
38
38
import { normCase } from '../../common/platform/fs-paths' ;
39
39
import { PythonEnvType } from '../../pythonEnvironments/base/info' ;
40
- import { ITerminalEnvVarCollectionService } from '../types' ;
41
- import { ShellIntegrationShells } from './shellIntegration' ;
40
+ import { IShellIntegrationService , ITerminalEnvVarCollectionService } from '../types' ;
42
41
import { ProgressService } from '../../common/application/progressService' ;
43
42
44
43
@injectable ( )
@@ -80,6 +79,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
80
79
@inject ( IWorkspaceService ) private workspaceService : IWorkspaceService ,
81
80
@inject ( IConfigurationService ) private readonly configurationService : IConfigurationService ,
82
81
@inject ( IPathUtils ) private readonly pathUtils : IPathUtils ,
82
+ @inject ( IShellIntegrationService ) private readonly shellIntegrationService : IShellIntegrationService ,
83
83
) {
84
84
this . separator = platform . osType === OSType . Windows ? ';' : ':' ;
85
85
this . progressService = new ProgressService ( this . shell ) ;
@@ -121,7 +121,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
121
121
this . disposables ,
122
122
) ;
123
123
const { shell } = this . applicationEnvironment ;
124
- const isActive = this . isShellIntegrationActive ( shell ) ;
124
+ const isActive = await this . shellIntegrationService . isWorking ( shell ) ;
125
125
const shellType = identifyShellFromShellPath ( shell ) ;
126
126
if ( ! isActive && shellType !== TerminalShellType . commandPrompt ) {
127
127
traceWarn ( `Shell integration is not active, environment activated maybe overriden by the shell.` ) ;
@@ -139,7 +139,10 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
139
139
location : ProgressLocation . Window ,
140
140
title : Interpreters . activatingTerminals ,
141
141
} ) ;
142
- await this . _applyCollectionImpl ( resource , shell ) ;
142
+ await this . _applyCollectionImpl ( resource , shell ) . catch ( ( ex ) => {
143
+ traceError ( `Failed to apply terminal env vars` , shell , ex ) ;
144
+ return Promise . reject ( ex ) ; // Ensures progress indicator does not disappear in case of errors, so we can catch issues faster.
145
+ } ) ;
143
146
this . progressService . hideProgress ( ) ;
144
147
}
145
148
@@ -184,7 +187,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
184
187
185
188
// PS1 in some cases is a shell variable (not an env variable) so "env" might not contain it, calculate it in that case.
186
189
env . PS1 = await this . getPS1 ( shell , resource , env ) ;
187
- const prependOptions = this . getPrependOptions ( shell ) ;
190
+ const prependOptions = await this . getPrependOptions ( shell ) ;
188
191
189
192
// Clear any previously set env vars from collection
190
193
envVarCollection . clear ( ) ;
@@ -277,7 +280,7 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
277
280
// PS1 should be set but no PS1 was set.
278
281
return ;
279
282
}
280
- const config = this . isShellIntegrationActive ( shell ) ;
283
+ const config = await this . shellIntegrationService . isWorking ( shell ) ;
281
284
if ( ! config ) {
282
285
traceVerbose ( 'PS1 is not set when shell integration is disabled.' ) ;
283
286
return ;
@@ -332,8 +335,8 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
332
335
}
333
336
}
334
337
335
- private getPrependOptions ( shell : string ) : EnvironmentVariableMutatorOptions {
336
- const isActive = this . isShellIntegrationActive ( shell ) ;
338
+ private async getPrependOptions ( shell : string ) : Promise < EnvironmentVariableMutatorOptions > {
339
+ const isActive = await this . shellIntegrationService . isWorking ( shell ) ;
337
340
// Ideally we would want to prepend exactly once, either at shell integration or process creation.
338
341
// TODO: Stop prepending altogether once https://github.com/microsoft/vscode/issues/145234 is available.
339
342
return isActive
@@ -347,21 +350,6 @@ export class TerminalEnvVarCollectionService implements IExtensionActivationServ
347
350
} ;
348
351
}
349
352
350
- private isShellIntegrationActive ( shell : string ) : boolean {
351
- const isEnabled = this . workspaceService
352
- . getConfiguration ( 'terminal' )
353
- . get < boolean > ( 'integrated.shellIntegration.enabled' ) ! ;
354
- if ( isEnabled && ShellIntegrationShells . includes ( identifyShellFromShellPath ( shell ) ) ) {
355
- // Unfortunately shell integration could still've failed in remote scenarios, we can't know for sure:
356
- // https://code.visualstudio.com/docs/terminal/shell-integration#_automatic-script-injection
357
- return true ;
358
- }
359
- if ( ! isEnabled ) {
360
- traceVerbose ( 'Shell integrated is disabled in user settings.' ) ;
361
- }
362
- return false ;
363
- }
364
-
365
353
private getEnvironmentVariableCollection ( scope : EnvironmentVariableScope = { } ) {
366
354
const envVarCollection = this . context . environmentVariableCollection as GlobalEnvironmentVariableCollection ;
367
355
return envVarCollection . getScoped ( scope ) ;
0 commit comments