@@ -36,9 +36,24 @@ let lastPtyId = 0;
3636export class PtyHostService extends Disposable implements IPtyService {
3737 declare readonly _serviceBrand : undefined ;
3838
39- private _connection : IPtyHostConnection ;
39+ private __connection ? : IPtyHostConnection ;
4040 // ProxyChannel is not used here because events get lost when forwarding across multiple proxies
41- private _proxy : IPtyService ;
41+ private __proxy ?: IPtyService ;
42+
43+ private get _connection ( ) : IPtyHostConnection {
44+ this . _ensurePtyHost ( ) ;
45+ return this . __connection ! ;
46+ }
47+ private get _proxy ( ) : IPtyService {
48+ this . _ensurePtyHost ( ) ;
49+ return this . __proxy ! ;
50+ }
51+
52+ private _ensurePtyHost ( ) {
53+ if ( ! this . __connection ) {
54+ [ this . __connection , this . __proxy ] = this . _startPtyHost ( ) ;
55+ }
56+ }
4257
4358 private readonly _shellEnv : Promise < typeof process . env > ;
4459 private readonly _resolveVariablesRequestStore : RequestStore < string [ ] , { workspaceId : string ; originalText : string [ ] } > ;
@@ -93,14 +108,13 @@ export class PtyHostService extends Disposable implements IPtyService {
93108 this . _resolveVariablesRequestStore = this . _register ( new RequestStore ( undefined , this . _logService ) ) ;
94109 this . _resolveVariablesRequestStore . onCreateRequest ( this . _onPtyHostRequestResolveVariables . fire , this . _onPtyHostRequestResolveVariables ) ;
95110
96- [ this . _connection , this . _proxy ] = this . _startPtyHost ( ) ;
97-
98- this . _register ( this . _configurationService . onDidChangeConfiguration ( async e => {
99- if ( e . affectsConfiguration ( TerminalSettingId . IgnoreProcessNames ) ) {
100- await this . _refreshIgnoreProcessNames ( ) ;
101- }
102- } ) ) ;
103- this . _refreshIgnoreProcessNames ( ) ;
111+ // Force the pty host to start as the first window is starting if the starter has that
112+ // capability
113+ if ( this . _ptyHostStarter . onBeforeWindowConnection ) {
114+ Event . once ( this . _ptyHostStarter . onBeforeWindowConnection ) ( ( ) => this . _ensurePtyHost ( ) ) ;
115+ } else {
116+ this . _ensurePtyHost ( ) ;
117+ }
104118 }
105119
106120 private get _ignoreProcessNames ( ) : string [ ] {
@@ -126,6 +140,7 @@ export class PtyHostService extends Disposable implements IPtyService {
126140 }
127141
128142 private _startPtyHost ( ) : [ IPtyHostConnection , IPtyService ] {
143+ this . _logService . info ( 'startPtyHost' , new Error ( ) . stack ) ;
129144 const connection = this . _ptyHostStarter . start ( lastPtyId ) ;
130145 const client = connection . client ;
131146
@@ -166,6 +181,16 @@ export class PtyHostService extends Disposable implements IPtyService {
166181 this . _register ( new RemoteLoggerChannelClient ( this . _loggerService , client . getChannel ( TerminalIpcChannels . Logger ) ) ) ;
167182 } ) ;
168183
184+ this . __connection = connection ;
185+ this . __proxy = proxy ;
186+
187+ this . _register ( this . _configurationService . onDidChangeConfiguration ( async e => {
188+ if ( e . affectsConfiguration ( TerminalSettingId . IgnoreProcessNames ) ) {
189+ await this . _refreshIgnoreProcessNames ( ) ;
190+ }
191+ } ) ) ;
192+ this . _refreshIgnoreProcessNames ( ) ;
193+
169194 return [ connection , proxy ] ;
170195 }
171196
@@ -314,7 +339,7 @@ export class PtyHostService extends Disposable implements IPtyService {
314339 async restartPtyHost ( ) : Promise < void > {
315340 this . _disposePtyHost ( ) ;
316341 this . _isResponsive = true ;
317- [ this . _connection , this . _proxy ] = this . _startPtyHost ( ) ;
342+ this . _startPtyHost ( ) ;
318343 }
319344
320345 private _disposePtyHost ( ) : void {
0 commit comments