@@ -5,6 +5,7 @@ import { injectable, inject } from 'inversify';
5
5
import { IApplicationShell , ITerminalManager , IWorkspaceService } from '../../common/application/types' ;
6
6
import { identifyShellFromShellPath } from '../../common/terminal/shellDetectors/baseShellDetector' ;
7
7
import { TerminalShellType } from '../../common/terminal/types' ;
8
+ import { IPersistentStateFactory } from '../../common/types' ;
8
9
import { createDeferred , sleep } from '../../common/utils/async' ;
9
10
import { cache } from '../../common/utils/decorators' ;
10
11
import { traceError , traceInfo , traceVerbose } from '../../logging' ;
@@ -22,12 +23,22 @@ const ShellIntegrationShells = [
22
23
TerminalShellType . fish ,
23
24
] ;
24
25
26
+ export const isShellIntegrationWorkingKey = 'SHELL_INTEGRATION_WORKING_KEY' ;
27
+
25
28
@injectable ( )
26
29
export class ShellIntegrationService implements IShellIntegrationService {
30
+ /**
31
+ * It seems to have a couple of issues:
32
+ * * Ends up cluterring terminal history
33
+ * * Does not work for hidden terminals: https://github.com/microsoft/vscode/issues/199611
34
+ */
35
+ private readonly USE_COMMAND_APPROACH = false ;
36
+
27
37
constructor (
28
38
@inject ( ITerminalManager ) private readonly terminalManager : ITerminalManager ,
29
39
@inject ( IApplicationShell ) private readonly appShell : IApplicationShell ,
30
40
@inject ( IWorkspaceService ) private readonly workspaceService : IWorkspaceService ,
41
+ @inject ( IPersistentStateFactory ) private readonly persistentStateFactory : IPersistentStateFactory ,
31
42
) { }
32
43
33
44
public async isWorking ( shell : string ) : Promise < boolean > {
@@ -50,6 +61,23 @@ export class ShellIntegrationService implements IShellIntegrationService {
50
61
if ( ! isSupposedToWork ) {
51
62
return false ;
52
63
}
64
+ if ( ! this . USE_COMMAND_APPROACH ) {
65
+ // For now, based on problems with using the command approach, assume it always works.
66
+ return true ;
67
+ }
68
+ const key = `${ isShellIntegrationWorkingKey } _${ shellType } ` ;
69
+ const persistedResult = this . persistentStateFactory . createGlobalPersistentState < boolean > ( key ) ;
70
+ if ( persistedResult . value !== undefined ) {
71
+ return persistedResult . value ;
72
+ }
73
+ const result = await this . checkIfWorkingByRunningCommand ( shell ) ;
74
+ // Persist result to storage to avoid running commands unncecessary.
75
+ await persistedResult . updateValue ( result ) ;
76
+ return result ;
77
+ }
78
+
79
+ private async checkIfWorkingByRunningCommand ( shell : string ) : Promise < boolean > {
80
+ const shellType = identifyShellFromShellPath ( shell ) ;
53
81
const deferred = createDeferred < void > ( ) ;
54
82
const timestamp = new Date ( ) . getTime ( ) ;
55
83
const name = `Python ${ timestamp } ` ;
0 commit comments