mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 19:44:25 +01:00
make ext host ipc use message passing protocol api
This commit is contained in:
@@ -9,7 +9,7 @@ import nls = require('vs/nls');
|
||||
import pfs = require('vs/base/node/pfs');
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import paths = require('vs/base/common/paths');
|
||||
import { IMainProcessExtHostIPC } from 'vs/platform/extensions/node/ipcRemoteCom';
|
||||
import { IRemoteCom } from 'vs/platform/extensions/common/ipcRemoteCom';
|
||||
import { ExtHostExtensionService } from 'vs/workbench/api/node/extHostExtensionService';
|
||||
import { ExtHostThreadService } from 'vs/workbench/services/thread/common/extHostThreadService';
|
||||
import { RemoteTelemetryService } from 'vs/workbench/api/node/extHostTelemetry';
|
||||
@@ -37,7 +37,7 @@ export class ExtensionHostMain {
|
||||
private _environment: IEnvironment;
|
||||
private _extensionService: ExtHostExtensionService;
|
||||
|
||||
constructor(remoteCom: IMainProcessExtHostIPC, initData: IInitData) {
|
||||
constructor(remoteCom: IRemoteCom, initData: IInitData) {
|
||||
// services
|
||||
this._environment = initData.environment;
|
||||
this._contextService = new WorkspaceContextService(initData.contextService.workspace);
|
||||
|
||||
@@ -8,21 +8,18 @@
|
||||
import { onUnexpectedError } from 'vs/base/common/errors';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { ExtensionHostMain, exit } from 'vs/workbench/node/extensionHostMain';
|
||||
import { create as createIPC, IMainProcessExtHostIPC } from 'vs/platform/extensions/node/ipcRemoteCom';
|
||||
import { IRemoteCom, createProxyProtocol } from 'vs/platform/extensions/common/ipcRemoteCom';
|
||||
import marshalling = require('vs/base/common/marshalling');
|
||||
import { createQueuedSender } from 'vs/base/node/processes';
|
||||
import { IInitData } from 'vs/workbench/api/node/extHost.protocol';
|
||||
import { IMessagePassingProtocol } from 'vs/base/parts/ipc/common/ipc';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
|
||||
interface IRendererConnection {
|
||||
remoteCom: IMainProcessExtHostIPC;
|
||||
remoteCom: IRemoteCom;
|
||||
initData: IInitData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag set when in shutdown phase to avoid communicating to the main process.
|
||||
*/
|
||||
let isTerminating = false;
|
||||
|
||||
// This calls exit directly in case the initialization is not finished and we need to exit
|
||||
// Otherwise, if initialization completed we go to extensionHostMain.terminate()
|
||||
let onTerminate = function () {
|
||||
@@ -32,6 +29,32 @@ let onTerminate = function () {
|
||||
// Utility to not flood the process.send() with messages if it is busy catching up
|
||||
const queuedSender = createQueuedSender(process);
|
||||
|
||||
const protocol = new class implements IMessagePassingProtocol {
|
||||
|
||||
private _sender = createQueuedSender(process);
|
||||
private _onMessage = new Emitter<any>();
|
||||
private _terminating: boolean = false;
|
||||
|
||||
readonly onMessage: Event<any> = this._onMessage.event;
|
||||
|
||||
constructor() {
|
||||
process.on('message', (msg) => {
|
||||
if (msg.type === '__$terminate') {
|
||||
this._terminating = true;
|
||||
onTerminate();
|
||||
return;
|
||||
}
|
||||
this._onMessage.fire(msg);
|
||||
});
|
||||
}
|
||||
|
||||
send(data: any): void {
|
||||
if (!this._terminating) {
|
||||
this._sender.send(data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function connectToRenderer(): TPromise<IRendererConnection> {
|
||||
return new TPromise<IRendererConnection>((c, e) => {
|
||||
const stats: number[] = [];
|
||||
@@ -41,24 +64,7 @@ function connectToRenderer(): TPromise<IRendererConnection> {
|
||||
|
||||
let msg = marshalling.parse(raw);
|
||||
|
||||
const remoteCom = createIPC(data => {
|
||||
// Needed to avoid EPIPE errors in process.send below when a channel is closed
|
||||
if (isTerminating === true) {
|
||||
return;
|
||||
}
|
||||
queuedSender.send(data);
|
||||
stats.push(data.length);
|
||||
});
|
||||
|
||||
// Listen to all other messages
|
||||
process.on('message', (msg) => {
|
||||
if (msg.type === '__$terminate') {
|
||||
isTerminating = true;
|
||||
onTerminate();
|
||||
return;
|
||||
}
|
||||
remoteCom.handle(msg);
|
||||
});
|
||||
const remoteCom = createProxyProtocol(protocol);
|
||||
|
||||
// Print a console message when rejection isn't handled within N seconds. For details:
|
||||
// see https://nodejs.org/api/process.html#process_event_unhandledrejection
|
||||
|
||||
Reference in New Issue
Block a user