Skip to content

Commit 7993982

Browse files
committed
Create utility process pty host on Electron
1 parent 1de9210 commit 7993982

File tree

4 files changed

+69
-62
lines changed

4 files changed

+69
-62
lines changed

src/vs/code/electron-main/app.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,14 +931,13 @@ export class CodeApplication extends Disposable {
931931
graceTime: LocalReconnectConstants.GraceTime,
932932
shortGraceTime: LocalReconnectConstants.ShortGraceTime,
933933
scrollback: this.configurationService.getValue<number>(TerminalSettingId.PersistentSessionScrollback) ?? 100
934-
}, this.environmentMainService);
934+
}, this.environmentMainService, this.lifecycleMainService, this.logService);
935935
const ptyHostService = new PtyHostService(
936936
ptyHostStarter,
937937
this.configurationService,
938938
this.logService,
939939
this.loggerService
940940
);
941-
ptyHostService.initialize();
942941
services.set(ILocalPtyService, ptyHostService);
943942

944943
// External terminal

src/vs/platform/terminal/electron-main/electronPtyHostStarter.ts

Lines changed: 51 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,60 +4,67 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { IEnvironmentService, INativeEnvironmentService } from 'vs/platform/environment/common/environment';
7+
import { parsePtyHostDebugPort } from 'vs/platform/environment/node/environmentService';
8+
import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifecycleMainService';
9+
import { ILogService } from 'vs/platform/log/common/log';
10+
import { NullTelemetryService } from 'vs/platform/telemetry/common/telemetryUtils';
711
import { IReconnectConstants } from 'vs/platform/terminal/common/terminal';
8-
import { NodePtyHostStarter } from 'vs/platform/terminal/node/nodePtyHostStarter';
912
import { IPtyHostConnection, IPtyHostStarter } from 'vs/platform/terminal/node/ptyHost';
10-
// import { FileAccess } from 'vs/base/common/network';
11-
// import { Client, IIPCOptions } from 'vs/base/parts/ipc/node/ipc.cp';
12-
// import { parsePtyHostDebugPort } from 'vs/platform/environment/node/environmentService';
13-
// import { UtilityProcess } from 'vs/platform/utilityProcess/electron-main/utilityProcess';
13+
import { UtilityProcess } from 'vs/platform/utilityProcess/electron-main/utilityProcess';
14+
import { Client as MessagePortClient } from 'vs/base/parts/ipc/electron-main/ipc.mp';
1415

1516
export class ElectronPtyHostStarter implements IPtyHostStarter {
1617

17-
// private utilityProcess: UtilityProcess | undefined = undefined;
18+
private utilityProcess: UtilityProcess | undefined = undefined;
1819

1920
constructor(
2021
private readonly _reconnectConstants: IReconnectConstants,
21-
@IEnvironmentService private readonly _environmentService: INativeEnvironmentService
22+
@IEnvironmentService private readonly _environmentService: INativeEnvironmentService,
23+
@ILifecycleMainService private readonly _lifecycleMainService: ILifecycleMainService,
24+
@ILogService private readonly _logService: ILogService
2225
) {
2326
}
2427

25-
start(lastPtyId: number): IPtyHostConnection {
26-
return new NodePtyHostStarter(this._reconnectConstants, this._environmentService).start(lastPtyId);
27-
28-
// console.log('use utility proc');
29-
30-
// // TODO: Convert to use utility process
31-
// const opts: IIPCOptions = {
32-
// serverName: 'Pty Host',
33-
// args: ['--type=ptyHost', '--logsPath', this._environmentService.logsHome.fsPath],
34-
// env: {
35-
// VSCODE_LAST_PTY_ID: lastPtyId,
36-
// VSCODE_PTY_REMOTE: this._isRemote,
37-
// VSCODE_AMD_ENTRYPOINT: 'vs/platform/terminal/node/ptyHostMain',
38-
// VSCODE_PIPE_LOGGING: 'true',
39-
// VSCODE_VERBOSE_LOGGING: 'true', // transmit console logs from server to client,
40-
// VSCODE_RECONNECT_GRACE_TIME: this._reconnectConstants.graceTime,
41-
// VSCODE_RECONNECT_SHORT_GRACE_TIME: this._reconnectConstants.shortGraceTime,
42-
// VSCODE_RECONNECT_SCROLLBACK: this._reconnectConstants.scrollback
43-
// }
44-
// };
45-
46-
// const ptyHostDebug = parsePtyHostDebugPort(this._environmentService.args, this._environmentService.isBuilt);
47-
// if (ptyHostDebug) {
48-
// if (ptyHostDebug.break && ptyHostDebug.port) {
49-
// opts.debugBrk = ptyHostDebug.port;
50-
// } else if (!ptyHostDebug.break && ptyHostDebug.port) {
51-
// opts.debug = ptyHostDebug.port;
52-
// }
53-
// }
54-
55-
// const client = new Client(FileAccess.asFileUri('bootstrap-fork').fsPath, opts);
56-
57-
// return {
58-
// client,
59-
// dispose: client.dispose,
60-
// onDidProcessExit: client.onDidProcessExit
61-
// };
28+
async start(lastPtyId: number): Promise<IPtyHostConnection> {
29+
this.utilityProcess = new UtilityProcess(this._logService, NullTelemetryService, this._lifecycleMainService);
30+
31+
const inspectParams = parsePtyHostDebugPort(this._environmentService.args, this._environmentService.isBuilt);
32+
let execArgv: string[] | undefined = undefined;
33+
if (inspectParams) {
34+
execArgv = ['--nolazy'];
35+
if (inspectParams.break) {
36+
execArgv.push(`--inspect-brk=${inspectParams.port}`);
37+
} else if (!inspectParams.break) {
38+
execArgv.push(`--inspect=${inspectParams.port}`);
39+
}
40+
}
41+
42+
this.utilityProcess.start({
43+
type: 'ptyHost',
44+
entryPoint: 'vs/platform/terminal/node/ptyHostMain',
45+
payload: this._createPtyHostConfiguration(lastPtyId),
46+
execArgv
47+
});
48+
49+
const port = this.utilityProcess.connect();
50+
const client = new MessagePortClient(port, 'ptyHost');
51+
52+
return {
53+
client,
54+
dispose: client.dispose,
55+
onDidProcessExit: this.utilityProcess.onExit
56+
};
57+
}
58+
59+
private _createPtyHostConfiguration(lastPtyId: number) {
60+
return {
61+
VSCODE_LAST_PTY_ID: lastPtyId,
62+
VSCODE_AMD_ENTRYPOINT: 'vs/platform/terminal/node/ptyHostMain',
63+
VSCODE_PIPE_LOGGING: 'true',
64+
VSCODE_VERBOSE_LOGGING: 'true', // transmit console logs from server to client,
65+
VSCODE_RECONNECT_GRACE_TIME: this._reconnectConstants.graceTime,
66+
VSCODE_RECONNECT_SHORT_GRACE_TIME: this._reconnectConstants.shortGraceTime,
67+
VSCODE_RECONNECT_SCROLLBACK: this._reconnectConstants.scrollback
68+
};
6269
}
6370
}

src/vs/platform/terminal/node/ptyHost.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ export interface IPtyHostStarter {
1919
* @param lastPtyId Tracks the last terminal ID from the pty host so we can give it to the new
2020
* pty host if it's restarted and avoid ID conflicts.
2121
*/
22-
start(lastPtyId: number): IPtyHostConnection;
22+
start(lastPtyId: number): IPtyHostConnection | Promise<IPtyHostConnection>;
2323
}

src/vs/platform/terminal/node/ptyHostService.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ let lastPtyId = 0;
3636
export class PtyHostService extends Disposable implements IPtyService {
3737
declare readonly _serviceBrand: undefined;
3838

39-
private _connection: IPtyHostConnection;
39+
// TODO: Avoid ! ?
40+
private _connection!: IPtyHostConnection;
4041
// ProxyChannel is not used here because events get lost when forwarding across multiple proxies
41-
private _proxy: IPtyService;
42+
private _proxy!: IPtyService;
4243

4344
private readonly _shellEnv: Promise<typeof process.env>;
4445
private readonly _resolveVariablesRequestStore: RequestStore<string[], { workspaceId: string; originalText: string[] }>;
@@ -93,17 +94,17 @@ export class PtyHostService extends Disposable implements IPtyService {
9394
this._resolveVariablesRequestStore = this._register(new RequestStore(undefined, this._logService));
9495
this._resolveVariablesRequestStore.onCreateRequest(this._onPtyHostRequestResolveVariables.fire, this._onPtyHostRequestResolveVariables);
9596

96-
[this._connection, this._proxy] = this._startPtyHost();
97+
this._startPtyHost().then(value => {
98+
this._connection = value[0];
99+
this._proxy = value[1];
97100

98-
this._register(this._configurationService.onDidChangeConfiguration(async e => {
99-
if (e.affectsConfiguration(TerminalSettingId.IgnoreProcessNames)) {
100-
await this._refreshIgnoreProcessNames();
101-
}
102-
}));
103-
}
104-
105-
initialize(): void {
106-
this._refreshIgnoreProcessNames();
101+
this._register(this._configurationService.onDidChangeConfiguration(async e => {
102+
if (e.affectsConfiguration(TerminalSettingId.IgnoreProcessNames)) {
103+
await this._refreshIgnoreProcessNames();
104+
}
105+
}));
106+
this._refreshIgnoreProcessNames();
107+
});
107108
}
108109

109110
private get _ignoreProcessNames(): string[] {
@@ -128,8 +129,8 @@ export class PtyHostService extends Disposable implements IPtyService {
128129
}
129130
}
130131

131-
private _startPtyHost(): [IPtyHostConnection, IPtyService] {
132-
const connection = this._ptyHostStarter.start(lastPtyId);
132+
private async _startPtyHost(): Promise<[IPtyHostConnection, IPtyService]> {
133+
const connection = await this._ptyHostStarter.start(lastPtyId);
133134
const client = connection.client;
134135

135136
this._onPtyHostStart.fire();
@@ -317,7 +318,7 @@ export class PtyHostService extends Disposable implements IPtyService {
317318
async restartPtyHost(): Promise<void> {
318319
this._isResponsive = true;
319320
this._disposePtyHost();
320-
[this._connection, this._proxy] = this._startPtyHost();
321+
[this._connection, this._proxy] = await this._startPtyHost();
321322
}
322323

323324
private _disposePtyHost(): void {

0 commit comments

Comments
 (0)