44 *--------------------------------------------------------------------------------------------*/
55
66import { IDisposable , dispose } from 'vs/base/common/lifecycle' ;
7- import { ITerminalService , ITerminalInstance , IShellLaunchConfig , ITerminalProcessExtHostProxy , ITerminalProcessExtHostRequest , ITerminalDimensions , EXT_HOST_CREATION_DELAY , IAvailableShellsRequest } from 'vs/workbench/contrib/terminal/common/terminal' ;
7+ import { ITerminalService , ITerminalInstance , IShellLaunchConfig , ITerminalProcessExtHostProxy , ITerminalProcessExtHostRequest , ITerminalDimensions , EXT_HOST_CREATION_DELAY , IAvailableShellsRequest , IDefaultShellAndArgsRequest } from 'vs/workbench/contrib/terminal/common/terminal' ;
88import { ExtHostContext , ExtHostTerminalServiceShape , MainThreadTerminalServiceShape , MainContext , IExtHostContext , ShellLaunchConfigDto } from 'vs/workbench/api/common/extHost.protocol' ;
99import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers' ;
1010import { UriComponents , URI } from 'vs/base/common/uri' ;
1111import { StopWatch } from 'vs/base/common/stopwatch' ;
1212import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal' ;
13+ import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService' ;
1314
1415@extHostNamedCustomer ( MainContext . MainThreadTerminalService )
1516export class MainThreadTerminalService implements MainThreadTerminalServiceShape {
@@ -24,7 +25,8 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
2425 constructor (
2526 extHostContext : IExtHostContext ,
2627 @ITerminalService private readonly _terminalService : ITerminalService ,
27- @ITerminalInstanceService readonly terminalInstanceService : ITerminalInstanceService
28+ @ITerminalInstanceService readonly terminalInstanceService : ITerminalInstanceService ,
29+ @IRemoteAgentService readonly _remoteAgentService : IRemoteAgentService
2830 ) {
2931 this . _proxy = extHostContext . getProxy ( ExtHostContext . ExtHostTerminalService ) ;
3032 this . _remoteAuthority = extHostContext . remoteAuthority ;
@@ -51,7 +53,7 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
5153
5254 // ITerminalInstanceService listeners
5355 if ( terminalInstanceService . onRequestDefaultShellAndArgs ) {
54- this . _toDispose . push ( terminalInstanceService . onRequestDefaultShellAndArgs ( r => this . _proxy . $requestDefaultShellAndArgs ( ) . then ( e => r ( e . shell , e . args ) ) ) ) ;
56+ this . _toDispose . push ( terminalInstanceService . onRequestDefaultShellAndArgs ( e => this . _onRequestDefaultShellAndArgs ( e ) ) ) ;
5557 }
5658
5759 // Set initial ext host state
@@ -291,10 +293,24 @@ export class MainThreadTerminalService implements MainThreadTerminalServiceShape
291293 this . _terminalProcesses [ terminalId ] . emitLatency ( sum / COUNT ) ;
292294 }
293295
296+ private _isPrimaryExtHost ( ) : boolean {
297+ // The "primary" ext host is the remote ext host if there is one, otherwise the local
298+ const conn = this . _remoteAgentService . getConnection ( ) ;
299+ if ( conn ) {
300+ return this . _remoteAuthority === conn . remoteAuthority ;
301+ }
302+ return true ;
303+ }
304+
294305 private _onRequestAvailableShells ( request : IAvailableShellsRequest ) : void {
295- if ( request . remoteAuthority !== this . _remoteAuthority ) {
296- return ;
306+ if ( this . _isPrimaryExtHost ( ) ) {
307+ this . _proxy . $requestAvailableShells ( ) . then ( e => request ( e ) ) ;
308+ }
309+ }
310+
311+ private _onRequestDefaultShellAndArgs ( request : IDefaultShellAndArgsRequest ) : void {
312+ if ( this . _isPrimaryExtHost ( ) ) {
313+ this . _proxy . $requestDefaultShellAndArgs ( ) . then ( e => request ( e . shell , e . args ) ) ;
297314 }
298- this . _proxy . $requestAvailableShells ( ) . then ( e => request . callback ( e ) ) ;
299315 }
300316}
0 commit comments