Skip to content

Commit bdd1572

Browse files
committed
Push ext host check to mainThread, apply fix to request defaults too
Fixes microsoft#76049
1 parent 00eee14 commit bdd1572

3 files changed

Lines changed: 28 additions & 17 deletions

File tree

src/vs/workbench/api/browser/mainThreadTerminalService.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { 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';
88
import { ExtHostContext, ExtHostTerminalServiceShape, MainThreadTerminalServiceShape, MainContext, IExtHostContext, ShellLaunchConfigDto } from 'vs/workbench/api/common/extHost.protocol';
99
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
1010
import { UriComponents, URI } from 'vs/base/common/uri';
1111
import { StopWatch } from 'vs/base/common/stopwatch';
1212
import { ITerminalInstanceService } from 'vs/workbench/contrib/terminal/browser/terminal';
13+
import { IRemoteAgentService } from 'vs/workbench/services/remote/common/remoteAgentService';
1314

1415
@extHostNamedCustomer(MainContext.MainThreadTerminalService)
1516
export 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
}

src/vs/workbench/contrib/terminal/common/terminal.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -758,8 +758,11 @@ export interface ITerminalProcessExtHostRequest {
758758
}
759759

760760
export interface IAvailableShellsRequest {
761-
remoteAuthority: string | null;
762-
callback: (shells: IShellDefinition[]) => void;
761+
(shells: IShellDefinition[]): void;
762+
}
763+
764+
export interface IDefaultShellAndArgsRequest {
765+
(shell: string, args: string[] | string | undefined): void;
763766
}
764767

765768
export enum LinuxDistro {
@@ -796,7 +799,3 @@ export interface ITerminalChildProcess {
796799
getCwd(): Promise<string>;
797800
getLatency(): Promise<number>;
798801
}
799-
800-
export interface IDefaultShellAndArgsRequest {
801-
(shell: string, args: string[] | string | undefined): void;
802-
}

src/vs/workbench/contrib/terminal/common/terminalService.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,6 @@ export abstract class TerminalService implements ITerminalService {
563563
}
564564

565565
private _detectWindowsShells(): Promise<IShellDefinition[]> {
566-
const conn = this._remoteAgentService.getConnection();
567-
return new Promise(r => this._onRequestAvailableShells.fire({
568-
remoteAuthority: conn ? conn.remoteAuthority : null,
569-
callback: r
570-
}));
566+
return new Promise(r => this._onRequestAvailableShells.fire(r));
571567
}
572568
}

0 commit comments

Comments
 (0)