mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 08:06:04 +00:00
simplify shared process startup
This commit is contained in:
parent
faf07be9e2
commit
cc8b65c8c8
2 changed files with 11 additions and 57 deletions
|
@ -5,57 +5,21 @@
|
|||
|
||||
import * as cp from 'child_process';
|
||||
import URI from 'vs/base/common/uri';
|
||||
import pkg from 'vs/platform/package';
|
||||
import { IDisposable } from 'vs/base/common/lifecycle';
|
||||
import { assign } from 'vs/base/common/objects';
|
||||
import { IEnvironment } from 'vs/platform/workspace/common/workspace';
|
||||
import { IEnvironmentService } from 'vs/code/electron-main/env';
|
||||
import { ISettingsService } from 'vs/code/electron-main/settings';
|
||||
import { IUpdateService } from 'vs/code/electron-main/update-manager';
|
||||
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
const boostrapPath = URI.parse(require.toUrl('bootstrap')).fsPath;
|
||||
|
||||
function getEnvironment(envService: IEnvironmentService, updateManager: IUpdateService): IEnvironment {
|
||||
let configuration: IEnvironment = assign({}, envService.cliArgs);
|
||||
configuration.execPath = process.execPath;
|
||||
configuration.appName = envService.product.nameLong;
|
||||
configuration.appRoot = envService.appRoot;
|
||||
configuration.version = pkg.version;
|
||||
configuration.commitHash = envService.product.commit;
|
||||
configuration.appSettingsHome = envService.appSettingsHome;
|
||||
configuration.appSettingsPath = envService.appSettingsPath;
|
||||
configuration.appKeybindingsPath = envService.appKeybindingsPath;
|
||||
configuration.userExtensionsHome = envService.userExtensionsHome;
|
||||
configuration.isBuilt = envService.isBuilt;
|
||||
configuration.updateFeedUrl = updateManager.feedUrl;
|
||||
configuration.updateChannel = updateManager.channel;
|
||||
configuration.extensionsGallery = envService.product.extensionsGallery;
|
||||
function _spawnSharedProcess(): cp.ChildProcess {
|
||||
const env = assign({}, process.env, {
|
||||
AMD_ENTRYPOINT: 'vs/code/node/sharedProcessMain'
|
||||
});
|
||||
|
||||
return configuration;
|
||||
}
|
||||
|
||||
function _spawnSharedProcess(envService: IEnvironmentService, updateManager: IUpdateService, settingsManager: ISettingsService): cp.ChildProcess {
|
||||
// Make sure the nls configuration travels to the shared process.
|
||||
const opts = {
|
||||
env: assign(assign({}, process.env), {
|
||||
AMD_ENTRYPOINT: 'vs/code/node/sharedProcessMain'
|
||||
})
|
||||
};
|
||||
|
||||
const result = cp.fork(boostrapPath, ['--type=SharedProcess'], opts);
|
||||
const result = cp.fork(boostrapPath, ['--type=SharedProcess'], { env });
|
||||
|
||||
// handshake
|
||||
result.once('message', () => {
|
||||
result.send({
|
||||
configuration: {
|
||||
env: getEnvironment(envService, updateManager)
|
||||
},
|
||||
contextServiceOptions: {
|
||||
globalSettings: settingsManager.globalSettings
|
||||
}
|
||||
});
|
||||
});
|
||||
result.once('message', () => result.send('hey'));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -63,10 +27,6 @@ function _spawnSharedProcess(envService: IEnvironmentService, updateManager: IUp
|
|||
let spawnCount = 0;
|
||||
|
||||
export function spawnSharedProcess(accessor: ServicesAccessor): IDisposable {
|
||||
const envService = accessor.get(IEnvironmentService);
|
||||
const updateManager = accessor.get(IUpdateService);
|
||||
const settingsManager = accessor.get(ISettingsService);
|
||||
|
||||
let child: cp.ChildProcess;
|
||||
|
||||
const spawn = () => {
|
||||
|
@ -74,7 +34,7 @@ export function spawnSharedProcess(accessor: ServicesAccessor): IDisposable {
|
|||
return;
|
||||
}
|
||||
|
||||
child = _spawnSharedProcess(envService, updateManager, settingsManager);
|
||||
child = _spawnSharedProcess();
|
||||
child.on('exit', spawn);
|
||||
};
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import { TPromise } from 'vs/base/common/winjs.base';
|
|||
import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection';
|
||||
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
|
||||
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
|
||||
import { IConfiguration } from 'vs/platform/workspace/common/workspace';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
|
||||
import { IEventService } from 'vs/platform/event/common/event';
|
||||
|
@ -19,11 +18,6 @@ import { ExtensionsChannel } from 'vs/workbench/parts/extensions/common/extensio
|
|||
import { IExtensionsService } from 'vs/workbench/parts/extensions/common/extensions';
|
||||
import { ExtensionsService } from 'vs/workbench/parts/extensions/node/extensionsService';
|
||||
|
||||
interface IInitData {
|
||||
configuration: IConfiguration;
|
||||
contextServiceOptions: { settings: any };
|
||||
}
|
||||
|
||||
function quit(err?: Error) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
|
@ -45,7 +39,7 @@ function setupPlanB(parentPid: number): void {
|
|||
}, 5000);
|
||||
}
|
||||
|
||||
function main(server: Server, initData: IInitData): void {
|
||||
function main(server: Server): void {
|
||||
const services = new ServiceCollection();
|
||||
|
||||
services.set(IEventService, new SyncDescriptor(EventService));
|
||||
|
@ -98,8 +92,8 @@ function setupIPC(hook: string): TPromise<Server> {
|
|||
return setup(true);
|
||||
}
|
||||
|
||||
function handshake(): TPromise<IInitData> {
|
||||
return new TPromise<IInitData>((c, e) => {
|
||||
function handshake(): TPromise<void> {
|
||||
return new TPromise<void>((c, e) => {
|
||||
process.once('message', c);
|
||||
process.once('error', e);
|
||||
process.send('hello');
|
||||
|
@ -107,6 +101,6 @@ function handshake(): TPromise<IInitData> {
|
|||
}
|
||||
|
||||
TPromise.join<any>([setupIPC(process.env['VSCODE_SHARED_IPC_HOOK']), handshake()])
|
||||
.then(r => main(r[0], r[1]))
|
||||
.then(r => main(r[0]))
|
||||
.then(() => setupPlanB(process.env['VSCODE_PID']))
|
||||
.done(null, quit);
|
Loading…
Reference in a new issue