Skip to content

Commit 4c51579

Browse files
committed
driver as a standalone module
1 parent 7bcf857 commit 4c51579

12 files changed

Lines changed: 89 additions & 101 deletions

File tree

build/gulpfile.vscode.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const vscodeEntryPoints = _.flatten([
6767
const vscodeResources = [
6868
'out-build/main.js',
6969
'out-build/cli.js',
70+
'out-build/driver.js',
7071
'out-build/bootstrap.js',
7172
'out-build/bootstrap-amd.js',
7273
'out-build/paths.js',

src/bootstrap-amd.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ function uriFromPath(_path) {
1818
}
1919

2020
function readFile(file) {
21-
return new Promise(function(resolve, reject) {
22-
fs.readFile(file, 'utf8', function(err, data) {
21+
return new Promise(function (resolve, reject) {
22+
fs.readFile(file, 'utf8', function (err, data) {
2323
if (err) {
2424
reject(err);
2525
return;
@@ -35,7 +35,7 @@ var nlsConfig = rawNlsConfig ? JSON.parse(rawNlsConfig) : { availableLanguages:
3535
// We have a special location of the nls files. They come from a language pack
3636
if (nlsConfig._resolvedLanguagePackCoreLocation) {
3737
let bundles = Object.create(null);
38-
nlsConfig.loadBundle = function(bundle, language, cb) {
38+
nlsConfig.loadBundle = function (bundle, language, cb) {
3939
let result = bundles[bundle];
4040
if (result) {
4141
cb(undefined, result);
@@ -47,7 +47,7 @@ if (nlsConfig._resolvedLanguagePackCoreLocation) {
4747
bundles[bundle] = json;
4848
cb(undefined, json);
4949
})
50-
.catch(cb);
50+
.catch(cb);
5151
};
5252
}
5353

@@ -66,10 +66,13 @@ if (nlsConfig.pseudo) {
6666
});
6767
}
6868

69-
exports.bootstrap = function (entrypoint) {
69+
exports.bootstrap = function (entrypoint, onLoad, onError) {
7070
if (!entrypoint) {
7171
return;
7272
}
7373

74-
loader([entrypoint], function () { }, function (err) { console.error(err); });
74+
onLoad = onLoad || function () { };
75+
onError = onError || function (err) { console.error(err); };
76+
77+
loader([entrypoint], onLoad, onError);
7578
};
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6-
'use strict';
6+
const { bootstrap } = require('./bootstrap-amd');
77

8-
import { foo } from '../../src/vs/code/node/driverClient';
9-
10-
foo();
8+
bootstrap('vs/code/node/driver', ({ connect }) => {
9+
console.log(connect);
10+
});

src/vs/code/buildfile.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function createModuleDescription(name, exclude) {
1212
excludes = excludes.concat(exclude);
1313
}
1414
result.exclude= excludes;
15-
15+
1616
return result;
1717
}
1818

@@ -22,6 +22,7 @@ exports.collectModules= function() {
2222
createModuleDescription('vs/code/node/cli', []),
2323
createModuleDescription('vs/code/node/cliProcessMain', ['vs/code/node/cli']),
2424
createModuleDescription('vs/code/electron-browser/sharedProcess/sharedProcessMain', []),
25-
createModuleDescription('vs/code/electron-browser/issue/issueReporterMain', [])
25+
createModuleDescription('vs/code/electron-browser/issue/issueReporterMain', []),
26+
createModuleDescription('vs/code/node/driver', [])
2627
];
2728
};

src/vs/code/common/driver.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,46 @@
77

88
import { TPromise } from 'vs/base/common/winjs.base';
99
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
10+
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
1011

1112
export const ID = 'driverService';
12-
export const IDriverService = createDecorator<IDriverService>(ID);
13+
export const IDriver = createDecorator<IDriver>(ID);
1314

1415
export interface IWindow {
1516
id: string;
1617
}
1718

18-
export interface IDriverService {
19+
export interface IDriver {
1920
_serviceBrand: any;
2021
getWindows(): TPromise<IWindow[]>;
2122
}
23+
24+
25+
export interface IDriverChannel extends IChannel {
26+
call(command: 'getWindows'): TPromise<IWindow[]>;
27+
call(command: string, arg: any): TPromise<any>;
28+
}
29+
30+
export class DriverChannel implements IDriverChannel {
31+
32+
constructor(private service: IDriver) { }
33+
34+
call(command: string, arg?: any): TPromise<any> {
35+
switch (command) {
36+
case 'getWindows': return this.service.getWindows();
37+
}
38+
39+
return undefined;
40+
}
41+
}
42+
43+
export class DriverChannelClient implements IDriver {
44+
45+
_serviceBrand: any;
46+
47+
constructor(private channel: IDriverChannel) { }
48+
49+
getWindows(): TPromise<IWindow[]> {
50+
return this.channel.call('getWindows');
51+
}
52+
}

src/vs/code/common/driverIpc.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
'use strict';
7+
8+
import { TPromise } from 'vs/base/common/winjs.base';
9+
import { IDriver, IWindow, DriverChannel } from 'vs/code/common/driver';
10+
import { IWindowsMainService } from 'vs/platform/windows/electron-main/windows';
11+
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
12+
import { serve } from 'vs/base/parts/ipc/node/ipc.net';
13+
14+
class Driver implements IDriver {
15+
16+
_serviceBrand: any;
17+
18+
constructor(
19+
@IWindowsMainService protected windowsService: IWindowsMainService
20+
) { }
21+
22+
getWindows(): TPromise<IWindow[], any> {
23+
return TPromise.as(this.windowsService.getWindows().map(w => ({ id: `${w.id}` })));
24+
}
25+
}
26+
27+
export async function startDriver(handle: string, instantiationService: IInstantiationService): TPromise<void> {
28+
const server = await serve(handle);
29+
const driver = instantiationService.createInstance(Driver);
30+
const channel = new DriverChannel(driver);
31+
server.registerChannel('driver', channel);
32+
}
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
'use strict';
77

88
import { TPromise } from 'vs/base/common/winjs.base';
9-
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
9+
import { IDriver, DriverChannelClient } from 'vs/code/common/driver';
10+
import { connect as connectNet } from 'vs/base/parts/ipc/node/ipc.net';
1011

11-
export function foo() {
12-
return 1;
13-
}
12+
export async function connect(handle: string): TPromise<IDriver> {
13+
const client = await connectNet(handle, 'driverClient');
14+
const channel = client.getChannel('driver');
15+
return new DriverChannelClient(channel);
16+
}

test/driver/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/driver/package.json

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)