Skip to content

Remove IPC #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jul 16, 2018
Merged
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"license": "SEE LICENSE IN LICENSE.txt",
"dependencies": {
"lodash": "^4.17.10",
"node-ipc": "8.10.3",
"universal-analytics": "0.4.13",
"uuid": "^3.2.1",
"vscode-chrome-debug-core": "^3.23.11",
Expand All @@ -36,8 +35,6 @@
"@types/lodash": "^4.14.109",
"@types/mocha": "2.2.41",
"@types/node": "6.0.46",
"@types/source-map": "~0.1.0",
"chrome-remote-debug-protocol": "https://github.com/roblourens/chrome-remote-debug-protocol/tarball/master",
"mocha": "2.5.3",
"typescript": "2.6.2",
"vsce": "~1.36.0",
Expand Down
4 changes: 2 additions & 2 deletions src/analytics/analyticsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ export class AnalyticsService {

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

Services.workspaceConfigService().isAnalyticsEnabled = shouldEnableAnalytics;
Services.workspaceConfigService.isAnalyticsEnabled = shouldEnableAnalytics;
this.updateAnalyticsEnabled();
}

private updateAnalyticsEnabled() {
this._analyticsEnabled = Services.workspaceConfigService().isAnalyticsEnabled;
this._analyticsEnabled = Services.workspaceConfigService.isAnalyticsEnabled;

if(this._analyticsEnabled && !this._gua) {
this._gua = new GUAService('UA-111455-29', this._baseInfo);
Expand Down
14 changes: 14 additions & 0 deletions src/common/extensionProtocol.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export interface Request {
id: string;
service: string;
method: string;
args: any[];
}

export interface Response {
requestId: string;
result: Object;
}

export const BEFORE_DEBUG_START = "before-debug-start";
export const NS_DEBUG_ADAPTER_MESSAGE = "ns-debug-adapter-message";
48 changes: 34 additions & 14 deletions src/debug-adapter/nativeScriptDebugAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
import { IInitializeRequestArgs, ChromeDebugAdapter, IAttachRequestArgs, ISetBreakpointsArgs, ISetBreakpointsResponseBody, ILaunchRequestArgs, ITelemetryPropertyCollector } from 'vscode-chrome-debug-core';
import { OutputEvent, TerminatedEvent } from 'vscode-debugadapter';
import { ChromeDebugAdapter } from 'vscode-chrome-debug-core';
import { OutputEvent, TerminatedEvent, Event } from 'vscode-debugadapter';
import * as utils from '../common/utilities';
import {IosProject} from '../project/iosProject';
import {AndroidProject} from '../project/androidProject';
import { ChildProcess } from 'child_process';
import * as fs from 'fs';
import * as path from 'path';
import {DebugResult} from '../project/project';
import {Services} from '../services/debugAdapterServices'
import * as extProtocol from '../common/extensionProtocol';
import { DebugProtocol } from 'vscode-debugprotocol';
import {Logger} from '../common/logger';
import {NativeScriptCli} from '../project/nativeScriptCli';

export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
private _tnsProcess: ChildProcess;
private _idCounter = 0;
private _pendingRequests: Object= {};

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

public async launch(args: any, telemetryPropertyCollector?: ITelemetryPropertyCollector): Promise<void> {
public async launch(args: any): Promise<void> {
return await this.processRequestAndAttach(args);
}

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

public onExtensionResponse(response) {
this._pendingRequests[response.requestId](response.result);
delete this._pendingRequests[response.requestId];
}

private async processRequest(args: any) : Promise<any> {
args = this.translateArgs(args);
Services.appRoot = args.appRoot;
Services.extensionClient().cleanBeforeDebug();
const settings = await Services.extensionClient().getInitSettings();

Services.cliPath = settings.tnsPath || Services.cliPath;
this._session.sendEvent(new Event(extProtocol.BEFORE_DEBUG_START));

const tnsPath = await this.callRemoteMethod<string>('workspaceConfigService', 'tnsPath');
const cli = new NativeScriptCli(tnsPath, new Logger());

const project = args.platform == "ios" ?
new IosProject(args.appRoot, Services.cli()) :
new AndroidProject(args.appRoot, Services.cli());
new IosProject(args.appRoot, cli) :
new AndroidProject(args.appRoot, cli);

Services.extensionClient().analyticsLaunchDebugger({ request: args.request, platform: args.platform });
this.callRemoteMethod('analyticsService', 'launchDebugger', args.request, args.platform);

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

private readTeamId(appRoot): string {
return this.readXCConfig(appRoot, "DEVELOPMENT_TEAM");
}
}

private callRemoteMethod<T>(service: string, method: string, ...args: any[]): Promise<T> {
let request: extProtocol.Request = { id: `req${++this._idCounter}`, service: service, method: method, args: args };

return new Promise<T>((res, rej) => {
this._pendingRequests[request.id] = res;

this._session.sendEvent(new Event(extProtocol.NS_DEBUG_ADAPTER_MESSAGE, request));
});
}
}
73 changes: 0 additions & 73 deletions src/ipc/extensionClient.ts

This file was deleted.

23 changes: 0 additions & 23 deletions src/ipc/extensionProtocol.ts

This file was deleted.

4 changes: 0 additions & 4 deletions src/ipc/sockedId.ts

This file was deleted.

38 changes: 28 additions & 10 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import {Project} from './project/project';
import {IosProject} from './project/iosProject';
import {AndroidProject} from './project/androidProject';
import * as utils from './common/utilities';
import * as extProtocol from './common/extensionProtocol';

// this method is called when the extension is activated
export function activate(context: vscode.ExtensionContext) {
Services.globalState = context.globalState;
Services.cliPath = Services.workspaceConfigService().tnsPath || Services.cliPath;
Services.extensionServer().start();
Services.analyticsService().initialize();
Services.cliPath = Services.workspaceConfigService.tnsPath || Services.cliPath;

Services.analyticsService.initialize();

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

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

Services.analyticsService().runRunCommand(project.platformName());
Services.analyticsService.runRunCommand(project.platformName());

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

context.subscriptions.push(disposable);

Services.extensionServer().registerForCleanBeforeDebug(disposable);
beforeBuildDisposables.push(disposable);
};

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

context.subscriptions.push(vscode.debug.onDidReceiveDebugSessionCustomEvent(event => {
if(event.event === extProtocol.BEFORE_DEBUG_START) {
beforeBuildDisposables.forEach(disposable => disposable.dispose());
}

if(event.event === extProtocol.NS_DEBUG_ADAPTER_MESSAGE) {
const request = event.body as extProtocol.Request;
const service = Services[request.service];
const method = service[request.method];
const response = typeof method === 'function' ? service[request.method].call(service, ...request.args) : method;

if(response.then) {
response.then(actualResponse => event.session.customRequest("onExtensionResponse", { requestId: request.id, result: actualResponse }));

return;
}

event.session.customRequest("onExtensionResponse", { requestId: request.id, result: response })
}
}));

context.subscriptions.push(runIosCommand);
context.subscriptions.push(runAndroidCommand);
context.subscriptions.push(showOutputChannelCommand);
Expand All @@ -87,8 +109,4 @@ function createInfoChannel(cliVersion: string): vscode.OutputChannel {
channel.appendLine(`NativeScript CLI: ${cliVersion}`);

return channel;
}

export function deactivate() {
Services.extensionServer().stop();
}
2 changes: 0 additions & 2 deletions src/project/iosProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {Project, DebugResult} from './project';
import * as scanner from './streamScanner';
import {Version} from '../common/version';
import {NativeScriptCli} from './nativeScriptCli';
import {Services} from '../services/debugAdapterServices';
import {Tags} from '../common/logger';

export class IosProject extends Project {

Expand Down
21 changes: 0 additions & 21 deletions src/services/debugAdapterServices.ts

This file was deleted.

Loading