Skip to content

Commit ebadc75

Browse files
committed
Remove ipc
Use the debug adapter events
1 parent e0719c7 commit ebadc75

12 files changed

+86
-224
lines changed

package.json

-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
"license": "SEE LICENSE IN LICENSE.txt",
2727
"dependencies": {
2828
"lodash": "^4.17.10",
29-
"node-ipc": "8.10.3",
3029
"universal-analytics": "0.4.13",
3130
"uuid": "^3.2.1",
3231
"vscode-chrome-debug-core": "^3.23.11",
@@ -36,8 +35,6 @@
3635
"@types/lodash": "^4.14.109",
3736
"@types/mocha": "2.2.41",
3837
"@types/node": "6.0.46",
39-
"@types/source-map": "~0.1.0",
40-
"chrome-remote-debug-protocol": "https://github.com/roblourens/chrome-remote-debug-protocol/tarball/master",
4138
"mocha": "2.5.3",
4239
"typescript": "2.6.2",
4340
"vsce": "~1.36.0",

src/analytics/analyticsService.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ export class AnalyticsService {
100100

101101
this._globalState.update(AnalyticsService.HAS_ANALYTICS_PROMPT_SHOWN_KEY, true);
102102

103-
Services.workspaceConfigService().isAnalyticsEnabled = shouldEnableAnalytics;
103+
Services.workspaceConfigService.isAnalyticsEnabled = shouldEnableAnalytics;
104104
this.updateAnalyticsEnabled();
105105
}
106106

107107
private updateAnalyticsEnabled() {
108-
this._analyticsEnabled = Services.workspaceConfigService().isAnalyticsEnabled;
108+
this._analyticsEnabled = Services.workspaceConfigService.isAnalyticsEnabled;
109109

110110
if(this._analyticsEnabled && !this._gua) {
111111
this._gua = new GUAService('UA-111455-29', this._baseInfo);

src/common/extensionProtocol.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export interface Request {
2+
id: string;
3+
service: string;
4+
method: string;
5+
args: any[];
6+
}
7+
8+
export interface Response {
9+
requestId: string;
10+
result: Object;
11+
}
12+
13+
export const BEFORE_DEBUG_START = "before-debug-start";
14+
export const NS_DEBUG_ADAPTER_MESSAGE = "ns-debug-adapter-message";

src/debug-adapter/nativeScriptDebugAdapter.ts

+34-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
import { IInitializeRequestArgs, ChromeDebugAdapter, IAttachRequestArgs, ISetBreakpointsArgs, ISetBreakpointsResponseBody, ILaunchRequestArgs, ITelemetryPropertyCollector } from 'vscode-chrome-debug-core';
2-
import { OutputEvent, TerminatedEvent } from 'vscode-debugadapter';
1+
import { ChromeDebugAdapter } from 'vscode-chrome-debug-core';
2+
import { OutputEvent, TerminatedEvent, Event } from 'vscode-debugadapter';
33
import * as utils from '../common/utilities';
44
import {IosProject} from '../project/iosProject';
55
import {AndroidProject} from '../project/androidProject';
66
import { ChildProcess } from 'child_process';
77
import * as fs from 'fs';
88
import * as path from 'path';
99
import {DebugResult} from '../project/project';
10-
import {Services} from '../services/debugAdapterServices'
10+
import * as extProtocol from '../common/extensionProtocol';
11+
import { DebugProtocol } from 'vscode-debugprotocol';
12+
import {Logger} from '../common/logger';
13+
import {NativeScriptCli} from '../project/nativeScriptCli';
1114

1215
export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
1316
private _tnsProcess: ChildProcess;
17+
private _idCounter = 0;
18+
private _pendingRequests: Object= {};
1419

1520
public async attach(args: any): Promise<void> {
1621
return await this.processRequestAndAttach(args);
1722
}
1823

19-
public async launch(args: any, telemetryPropertyCollector?: ITelemetryPropertyCollector): Promise<void> {
24+
public async launch(args: any): Promise<void> {
2025
return await this.processRequestAndAttach(args);
2126
}
2227

@@ -39,19 +44,24 @@ export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
3944
return super.attach(transformedArgs);
4045
}
4146

47+
public onExtensionResponse(response) {
48+
this._pendingRequests[response.requestId](response.result);
49+
delete this._pendingRequests[response.requestId];
50+
}
51+
4252
private async processRequest(args: any) : Promise<any> {
4353
args = this.translateArgs(args);
44-
Services.appRoot = args.appRoot;
45-
Services.extensionClient().cleanBeforeDebug();
46-
const settings = await Services.extensionClient().getInitSettings();
4754

48-
Services.cliPath = settings.tnsPath || Services.cliPath;
55+
this._session.sendEvent(new Event(extProtocol.BEFORE_DEBUG_START));
56+
57+
const tnsPath = await this.callRemoteMethod<string>('workspaceConfigService', 'tnsPath');
58+
const cli = new NativeScriptCli(tnsPath, new Logger());
4959

5060
const project = args.platform == "ios" ?
51-
new IosProject(args.appRoot, Services.cli()) :
52-
new AndroidProject(args.appRoot, Services.cli());
61+
new IosProject(args.appRoot, cli) :
62+
new AndroidProject(args.appRoot, cli);
5363

54-
Services.extensionClient().analyticsLaunchDebugger({ request: args.request, platform: args.platform });
64+
this.callRemoteMethod('analyticsService', 'launchDebugger', args.request, args.platform);
5565

5666
// Run CLI Command
5767
this.log(`[NSDebugAdapter] Using tns CLI v${project.cli.version.version} on path '${project.cli.path}'\n`);
@@ -64,9 +74,9 @@ export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
6474
// For iOS the TeamID is required if there's more than one.
6575
// Therefore if not set, show selection to the user.
6676
if(args.platform && args.platform.toLowerCase() === 'ios') {
67-
let teamId = this.getTeamId(path.join(Services.appRoot, 'app'), tnsArgs);
77+
let teamId = this.getTeamId(path.join(args.appRoot, 'app'), tnsArgs);
6878
if(!teamId) {
69-
let selectedTeam = (await Services.extensionClient().selectTeam());
79+
let selectedTeam = await this.callRemoteMethod<{ id: string, name: string }>('iOSTeamService', 'selectTeam');
7080
if(selectedTeam) {
7181
// add the selected by the user Team Id
7282
tnsArgs = (tnsArgs || []).concat(['--teamId', selectedTeam.id]);
@@ -174,5 +184,15 @@ export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
174184

175185
private readTeamId(appRoot): string {
176186
return this.readXCConfig(appRoot, "DEVELOPMENT_TEAM");
177-
}
187+
}
188+
189+
private callRemoteMethod<T>(service: string, method: string, ...args: any[]): Promise<T> {
190+
let request: extProtocol.Request = { id: `req${++this._idCounter}`, service: service, method: method, args: args };
191+
192+
return new Promise<T>((res, rej) => {
193+
this._pendingRequests[request.id] = res;
194+
195+
this._session.sendEvent(new Event(extProtocol.NS_DEBUG_ADAPTER_MESSAGE, request));
196+
});
197+
}
178198
}

src/ipc/extensionClient.ts

-73
This file was deleted.

src/ipc/extensionProtocol.ts

-23
This file was deleted.

src/ipc/sockedId.ts

-4
This file was deleted.

src/main.ts

+28-10
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import {Project} from './project/project';
55
import {IosProject} from './project/iosProject';
66
import {AndroidProject} from './project/androidProject';
77
import * as utils from './common/utilities';
8+
import * as extProtocol from './common/extensionProtocol';
89

910
// this method is called when the extension is activated
1011
export function activate(context: vscode.ExtensionContext) {
1112
Services.globalState = context.globalState;
12-
Services.cliPath = Services.workspaceConfigService().tnsPath || Services.cliPath;
13-
Services.extensionServer().start();
14-
Services.analyticsService().initialize();
13+
Services.cliPath = Services.workspaceConfigService.tnsPath || Services.cliPath;
14+
15+
Services.analyticsService.initialize();
1516

1617
// Check if NativeScript CLI is installed globally and if it is compatible with the extension version
1718
let cliVersion = Services.cli().version;
@@ -24,6 +25,7 @@ export function activate(context: vscode.ExtensionContext) {
2425
channel.show();
2526
});
2627

28+
let beforeBuildDisposables = new Array<vscode.Disposable>();
2729
let runCommand = (project: Project) => {
2830
if (vscode.workspace.rootPath === undefined) {
2931
vscode.window.showErrorMessage('No workspace opened.');
@@ -35,7 +37,7 @@ export function activate(context: vscode.ExtensionContext) {
3537
runChannel.clear();
3638
runChannel.show(vscode.ViewColumn.Two);
3739

38-
Services.analyticsService().runRunCommand(project.platformName());
40+
Services.analyticsService.runRunCommand(project.platformName());
3941

4042
let tnsProcess = project.run();
4143
tnsProcess.on('error', err => {
@@ -60,8 +62,7 @@ export function activate(context: vscode.ExtensionContext) {
6062
};
6163

6264
context.subscriptions.push(disposable);
63-
64-
Services.extensionServer().registerForCleanBeforeDebug(disposable);
65+
beforeBuildDisposables.push(disposable);
6566
};
6667

6768
let runIosCommand = vscode.commands.registerCommand('nativescript.runIos', () => {
@@ -72,6 +73,27 @@ export function activate(context: vscode.ExtensionContext) {
7273
return runCommand(new AndroidProject(vscode.workspace.rootPath, Services.cli()));
7374
});
7475

76+
context.subscriptions.push(vscode.debug.onDidReceiveDebugSessionCustomEvent(event => {
77+
if(event.event === extProtocol.BEFORE_DEBUG_START) {
78+
beforeBuildDisposables.forEach(disposable => disposable.dispose());
79+
}
80+
81+
if(event.event === extProtocol.NS_DEBUG_ADAPTER_MESSAGE) {
82+
const request = event.body as extProtocol.Request;
83+
const service = Services[request.service];
84+
const method = service[request.method];
85+
const response = typeof method === 'function' ? service[request.method].call(service, ...request.args) : method;
86+
87+
if(response.then) {
88+
response.then(actualResponse => event.session.customRequest("onExtensionResponse", { requestId: request.id, result: actualResponse }));
89+
90+
return;
91+
}
92+
93+
event.session.customRequest("onExtensionResponse", { requestId: request.id, result: response })
94+
}
95+
}));
96+
7597
context.subscriptions.push(runIosCommand);
7698
context.subscriptions.push(runAndroidCommand);
7799
context.subscriptions.push(showOutputChannelCommand);
@@ -87,8 +109,4 @@ function createInfoChannel(cliVersion: string): vscode.OutputChannel {
87109
channel.appendLine(`NativeScript CLI: ${cliVersion}`);
88110

89111
return channel;
90-
}
91-
92-
export function deactivate() {
93-
Services.extensionServer().stop();
94112
}

src/project/iosProject.ts

-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import {Project, DebugResult} from './project';
55
import * as scanner from './streamScanner';
66
import {Version} from '../common/version';
77
import {NativeScriptCli} from './nativeScriptCli';
8-
import {Services} from '../services/debugAdapterServices';
9-
import {Tags} from '../common/logger';
108

119
export class IosProject extends Project {
1210

src/services/debugAdapterServices.ts

-21
This file was deleted.

0 commit comments

Comments
 (0)