Skip to content

Fix vscode 1.20 debugging #159

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"publisher": "Telerik",
"bugs": "https://github.com/NativeScript/nativescript-vscode-extension/issues",
"engines": {
"vscode": "^1.7.0"
"vscode": "^1.19.0"
},
"homepage": "https://www.nativescript.org/",
"categories": [
Expand All @@ -25,26 +25,24 @@
],
"license": "SEE LICENSE IN LICENSE.txt",
"dependencies": {
"vscode-chrome-debug-core": "3.9.1",
"vscode-chrome-debug-core": "~3.9.0",
"node-ipc": "8.10.3",
"source-map": "0.5.6",
"source-map": "0.6.1",
"xmlhttprequest": "https://github.com/telerik/node-XMLHttpRequest/tarball/master",
"universal-analytics": "0.4.13",
"vscode-debugadapter": "1.19.0",
"vscode-debugprotocol": "1.19.0"
"vscode-debugadapter": "1.26.0",
"vscode-debugprotocol": "1.26.0"
},
"devDependencies": {
"@types/es6-collections": "0.5.30",
"@types/es6-promise": "0.0.32",
"@types/mocha": "2.2.41",
"@types/node": "6.0.46",
"@types/source-map": "~0.1.0",
"chrome-remote-debug-protocol": "git://github.com/roblourens/chrome-remote-debug-protocol.git",
"mocha": "2.5.3",
"typescript": "~2.4.0",
"vsce": "1.22.0",
"vscode": "1.1.0",
"vscode-debugadapter-testsupport": "1.19.0"
"typescript": "2.6.2",
"vsce": "~1.36.0",
"vscode": "~1.1.10",
"vscode-debugadapter-testsupport": "1.26.0"
},
"scripts": {
"clean": "git clean -fdx",
Expand Down
8 changes: 0 additions & 8 deletions src/custom-typings/es6-impl/es6-impl.d.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/debug-adapter/adapter/adapterProxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ export class AdapterProxy {
.filter(transformer => request.command in transformer)
.reduce(
(p, transformer) => p.then(() => transformer[request.command](request.arguments, request.seq)),
Promise.resolve<void>());
Promise.resolve());
}

/**
* Pass the response body back through the transformers in reverse order. They modify the body in place.
*/
private transformResponse(request: DebugProtocol.Request, body: any): Promise<void> {
if (!body) {
return Promise.resolve<void>();
return Promise.resolve();
}

const bodyTransformMethodName = request.command + 'Response';
Expand All @@ -58,7 +58,7 @@ export class AdapterProxy {
.filter(transformer => bodyTransformMethodName in transformer)
.reduce(
(p, transformer) => p.then(() => transformer[bodyTransformMethodName](body, request.seq)),
Promise.resolve<void>());
Promise.resolve());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/debug-adapter/connection/iosConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export class IosConnection implements INSDebugConnection {
}

public enable() : Promise<void> {
return Promise.resolve<void>();
return Promise.resolve();
}

public close(): void {
Expand Down
18 changes: 8 additions & 10 deletions src/debug-adapter/webKitDebugAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import {DebugProtocol} from 'vscode-debugprotocol';
import {INSDebugConnection} from './connection/INSDebugConnection';
import {IosConnection} from './connection/iosConnection';
import {AndroidConnection} from './connection/androidConnection';
import {Project, DebugResult} from '../project/project';
import {IosProject} from '../project/iosProject';
import {AndroidProject} from '../project/androidProject';
import {DebugResult} from '../project/project';
import * as utils from '../common/utilities';
import {formatConsoleMessage} from './consoleHelper';
import {Services} from '../services/debugAdapterServices';
Expand Down Expand Up @@ -63,7 +61,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
private clearTargetContext(): void {
this._scriptsById = new Map<WebKitProtocol.Debugger.ScriptId, WebKitProtocol.Debugger.Script>();
this._committedBreakpointsByUrl = new Map<string, WebKitProtocol.Debugger.BreakpointId[]>();
this._setBreakpointsRequestQ = Promise.resolve<void>();
this._setBreakpointsRequestQ = Promise.resolve();
this._lastOutputEvent = null;
this.fireEvent({ seq: 0, type: 'event', event: 'clearTargetContext'});
}
Expand Down Expand Up @@ -129,8 +127,8 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
if (args.tnsOutput) {
Services.logger().addHandler(Handlers.createStreamHandler(fs.createWriteStream(args.tnsOutput)));
}
Services.logger().log(`initialize(${JSON.stringify(this._initArgs) })`);
Services.logger().log(`${args.request}(${JSON.stringify(args)})`);
Services.logger().log(`initialize(${JSON.stringify(this._initArgs) })\n`);
Services.logger().log(`${args.request}(${JSON.stringify(args)})\n`);
}

private async processRequest(args: DebugProtocol.IRequestArgs) {
Expand Down Expand Up @@ -368,7 +366,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
this._webKitConnection = null;
}

return Promise.resolve<void>();
return Promise.resolve();
}

public setBreakpoints(args: DebugProtocol.ISetBreakpointsArgs): Promise<DebugProtocol.ISetBreakpointsResponseBody> {
Expand Down Expand Up @@ -403,7 +401,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {

private _clearAllBreakpoints(url: string): Promise<void> {
if (!this._committedBreakpointsByUrl.has(url)) {
return Promise.resolve<void>();
return Promise.resolve();
}

// Remove breakpoints one at a time. Seems like it would be ok to send the removes all at once,
Expand All @@ -412,7 +410,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
// does not break there.
return this._committedBreakpointsByUrl.get(url).reduce((p, bpId) => {
return p.then(() => this._webKitConnection.debugger_removeBreakpoint(bpId)).then(() => { });
}, Promise.resolve<void>()).then(() => {
}, Promise.resolve()).then(() => {
this._committedBreakpointsByUrl.set(url, null);
});
}
Expand Down Expand Up @@ -621,7 +619,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
return { variables };
});
} else {
return Promise.resolve();
return Promise.resolve(null);
}
}

Expand Down
35 changes: 19 additions & 16 deletions src/ipc/extensionClient.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,41 @@
import * as path from 'path';
import * as os from 'os';
import * as crypto from 'crypto';
import * as extProtocol from './extensionProtocol';
let ipc = require('node-ipc');
import {Services} from "../services/debugAdapterServices";
import {getSocketId} from "./sockedId";

const ipc = require('node-ipc');

export class ExtensionClient {
private _appRoot: string;
private _idCounter = 0;
private _pendingRequests: Object;
private _socketId: string;

private _ipcClientInitialized: Promise<any>;

public static getTempFilePathForDirectory(directoryPath: string) {
let fileName: string = 'vsc-ns-ext-' + crypto.createHash('md5').update(directoryPath).digest("hex") + '.sock';
return path.join(os.tmpdir(), fileName);
}

constructor(appRoot: string) {
this._appRoot = appRoot;
this._idCounter = 0;
this._pendingRequests = {};

ipc.config.id = 'debug-adpater-' + process.pid;
this._socketId = getSocketId();

ipc.config.id = 'debug-adapter-' + process.pid;
ipc.config.retry = 1500;
ipc.config.maxRetries = 5;

this._ipcClientInitialized = new Promise((res, rej) => {
ipc.connectTo(
'extHost',
ExtensionClient.getTempFilePathForDirectory(this._appRoot),
this._socketId,
() => {
ipc.of.extHost.on('connect', () => {
ipc.of[this._socketId].on('connect', () => {
res();
});
ipc.of.extHost.on('extension-protocol-message', (response: extProtocol.Response) => {

ipc.of[this._socketId].on('error', error => {
Services.logger().log(`[ExtensionClient] error: ${JSON.stringify(error)}\n`);
});

ipc.of[this._socketId].on('extension-protocol-message', (response: extProtocol.Response) => {
(<(result: Object) => void>this._pendingRequests[response.requestId])(response.result);
});
}
Expand All @@ -41,10 +44,10 @@ export class ExtensionClient {
}

private callRemoteMethod(method: string, args?: Object): Promise<Object> {
let request: extProtocol.Request = { id: 'req' + (++this._idCounter), method: method, args: args };
let request: extProtocol.Request = {id: 'req' + (++this._idCounter), method: method, args: args};
return new Promise<Object>((res, rej) => {
this._pendingRequests[request.id] = res;
ipc.of.extHost.emit('extension-protocol-message', request);
ipc.of[this._socketId].emit('extension-protocol-message', request);
});
}

Expand Down
75 changes: 30 additions & 45 deletions src/ipc/extensionServer.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,34 @@
import * as path from 'path';
import * as os from 'os';
import * as fs from 'fs';
import * as crypto from 'crypto';
import * as vscode from 'vscode';
import {QuickPickItem} from 'vscode';
import * as extProtocol from './extensionProtocol';
import {Services} from '../services/extensionHostServices';
import {QuickPickItem} from "vscode";
import {getSocketId} from "./sockedId";

let ipc = require('node-ipc');

export class ExtensionServer {
private _isRunning: boolean;

public static getTempFilePathForDirectory(directoryPath: string) {
let fileName: string = 'vsc-ns-ext-' + crypto.createHash('md5').update(directoryPath).digest("hex") + '.sock';
return path.join(os.tmpdir(), fileName);
}

constructor() {
this._isRunning = false;
}

public getPipeHandlePath(): string {
return vscode.workspace.rootPath ?
ExtensionServer.getTempFilePathForDirectory(vscode.workspace.rootPath) :
null;
}

public start() {
if (!this._isRunning) {
let pipeHandlePath = this.getPipeHandlePath();
if (pipeHandlePath) {
ipc.serve(
pipeHandlePath,
() => {
ipc.server.on('extension-protocol-message', (data: extProtocol.Request, socket) => {
return (<Promise<Object>>this[data.method].call(this, data.args)).then(result => {
let response: extProtocol.Response = { requestId: data.id, result: result };
return ipc.server.emit(socket, 'extension-protocol-message', response);
});
ipc.config.id = getSocketId();
ipc.serve(
() => {
ipc.server.on('extension-protocol-message', (data: extProtocol.Request, socket) => {
return (<Promise<Object>>this[data.method].call(this, data.args)).then(result => {
let response: extProtocol.Response = {requestId: data.id, result: result};
return ipc.server.emit(socket, 'extension-protocol-message', response);
});
});
ipc.server.start();
this._isRunning = true;
}
});
ipc.server.start();
this._isRunning = true;
}
return this._isRunning;
}
Expand All @@ -60,7 +46,7 @@ export class ExtensionServer {

public getInitSettings(): Promise<extProtocol.InitSettingsResult> {
let tnsPath = Services.workspaceConfigService().tnsPath;
return Promise.resolve({ tnsPath: tnsPath });
return Promise.resolve({tnsPath: tnsPath});
}

public analyticsLaunchDebugger(args: extProtocol.AnalyticsLaunchDebuggerArgs): Promise<any> {
Expand Down Expand Up @@ -115,7 +101,7 @@ export class ExtensionServer {
let teamIds: any = {};
for (let file of files) {
let filePath = path.join(dir, file);
let data = fs.readFileSync(filePath, { encoding: "utf8" });
let data = fs.readFileSync(filePath, {encoding: "utf8"});
let teamId = this.getProvisioningProfileValue("TeamIdentifier", data);
let teamName = this.getProvisioningProfileValue("TeamName", data);
if (teamId) {
Expand All @@ -125,29 +111,28 @@ export class ExtensionServer {

let teamIdsArray = new Array<{ id: string, name: string }>();
for (let teamId in teamIds) {
teamIdsArray.push({ id: teamId, name: teamIds[teamId] });
teamIdsArray.push({id: teamId, name: teamIds[teamId]});
}

return teamIdsArray;
} catch (e) {
// no matter what happens, don't break
return new Array<{ id: string, name: string }>();
}
}
}

private getProvisioningProfileValue(name: string, text: string): string {
let findStr = "<key>" + name + "</key>";
let index = text.indexOf(findStr);
if (index > 0) {
index = text.indexOf("<string>", index + findStr.length);
if (index > 0) {
index += "<string>".length;
let endIndex = text.indexOf("</string>", index);
let result = text.substring(index, endIndex);
return result;
}
}

return null;
}
let findStr = "<key>" + name + "</key>";
let index = text.indexOf(findStr);
if (index > 0) {
index = text.indexOf("<string>", index + findStr.length);
if (index > 0) {
index += "<string>".length;
let endIndex = text.indexOf("</string>", index);
let result = text.substring(index, endIndex);
return result;
}
}
return null;
}
}
4 changes: 4 additions & 0 deletions src/ipc/sockedId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export function getSocketId(): string {
// let's KISS for now - I doubt users will want to simultaneously debug 2 apps anyway
return 'vs-ns-ext';
}
2 changes: 1 addition & 1 deletion src/tests/nsDebugClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class NsDebugClient extends DebugClient {
this.onNextTime(event).then(e => this.onNthTime(--n, event));
}

public assertSetBreakpoints(path: string, breakpoints: { line: number, condition?: string }[]): Promise<{}> {
public assertSetBreakpoints(path: string, breakpoints: { line: number, condition?: string }[]): Promise<void> {
return this.setBreakpointsRequest({
lines: breakpoints.map(b => b.line),
breakpoints: breakpoints,
Expand Down
7 changes: 5 additions & 2 deletions src/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"target": "es5",
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
Expand All @@ -10,9 +10,12 @@
"outDir": "../out",
"allowJs": true
},
"exclude": [
"node_modules",
"tests"
],
"files": [
// typescript definitions
"custom-typings/es6-impl/es6-impl.d.ts",
"custom-typings/universal-analytics/ua.d.ts",
"custom-typings/debugProtocolExtensions.d.ts",
"custom-typings/webKitProtocol.d.ts",
Expand Down