diff --git a/package.json b/package.json index 58fcc54..0bdfe45 100644 --- a/package.json +++ b/package.json @@ -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": [ @@ -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", diff --git a/src/custom-typings/es6-impl/es6-impl.d.ts b/src/custom-typings/es6-impl/es6-impl.d.ts deleted file mode 100644 index 2b1dbd1..0000000 --- a/src/custom-typings/es6-impl/es6-impl.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -interface String { - /** - * Returns true if the sequence of elements of searchString converted to a String is the - * same as the corresponding elements of this object (converted to a String) starting at - * position. Otherwise returns false. - */ - startsWith(searchString: string, position?: number): boolean; -} \ No newline at end of file diff --git a/src/debug-adapter/adapter/adapterProxy.ts b/src/debug-adapter/adapter/adapterProxy.ts index cc6b623..84887ab 100644 --- a/src/debug-adapter/adapter/adapterProxy.ts +++ b/src/debug-adapter/adapter/adapterProxy.ts @@ -40,7 +40,7 @@ export class AdapterProxy { .filter(transformer => request.command in transformer) .reduce( (p, transformer) => p.then(() => transformer[request.command](request.arguments, request.seq)), - Promise.resolve()); + Promise.resolve()); } /** @@ -48,7 +48,7 @@ export class AdapterProxy { */ private transformResponse(request: DebugProtocol.Request, body: any): Promise { if (!body) { - return Promise.resolve(); + return Promise.resolve(); } const bodyTransformMethodName = request.command + 'Response'; @@ -58,7 +58,7 @@ export class AdapterProxy { .filter(transformer => bodyTransformMethodName in transformer) .reduce( (p, transformer) => p.then(() => transformer[bodyTransformMethodName](body, request.seq)), - Promise.resolve()); + Promise.resolve()); } /** diff --git a/src/debug-adapter/connection/iosConnection.ts b/src/debug-adapter/connection/iosConnection.ts index 22725e6..76b92c2 100644 --- a/src/debug-adapter/connection/iosConnection.ts +++ b/src/debug-adapter/connection/iosConnection.ts @@ -171,7 +171,7 @@ export class IosConnection implements INSDebugConnection { } public enable() : Promise { - return Promise.resolve(); + return Promise.resolve(); } public close(): void { diff --git a/src/debug-adapter/webKitDebugAdapter.ts b/src/debug-adapter/webKitDebugAdapter.ts index aed6d1f..b2972c7 100644 --- a/src/debug-adapter/webKitDebugAdapter.ts +++ b/src/debug-adapter/webKitDebugAdapter.ts @@ -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'; @@ -63,7 +61,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter { private clearTargetContext(): void { this._scriptsById = new Map(); this._committedBreakpointsByUrl = new Map(); - this._setBreakpointsRequestQ = Promise.resolve(); + this._setBreakpointsRequestQ = Promise.resolve(); this._lastOutputEvent = null; this.fireEvent({ seq: 0, type: 'event', event: 'clearTargetContext'}); } @@ -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) { @@ -368,7 +366,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter { this._webKitConnection = null; } - return Promise.resolve(); + return Promise.resolve(); } public setBreakpoints(args: DebugProtocol.ISetBreakpointsArgs): Promise { @@ -403,7 +401,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter { private _clearAllBreakpoints(url: string): Promise { if (!this._committedBreakpointsByUrl.has(url)) { - return Promise.resolve(); + return Promise.resolve(); } // Remove breakpoints one at a time. Seems like it would be ok to send the removes all at once, @@ -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()).then(() => { + }, Promise.resolve()).then(() => { this._committedBreakpointsByUrl.set(url, null); }); } @@ -621,7 +619,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter { return { variables }; }); } else { - return Promise.resolve(); + return Promise.resolve(null); } } diff --git a/src/ipc/extensionClient.ts b/src/ipc/extensionClient.ts index 3aa26a8..7e7e3bc 100644 --- a/src/ipc/extensionClient.ts +++ b/src/ipc/extensionClient.ts @@ -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; - 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); }); } @@ -41,10 +44,10 @@ export class ExtensionClient { } private callRemoteMethod(method: string, args?: Object): Promise { - 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((res, rej) => { this._pendingRequests[request.id] = res; - ipc.of.extHost.emit('extension-protocol-message', request); + ipc.of[this._socketId].emit('extension-protocol-message', request); }); } diff --git a/src/ipc/extensionServer.ts b/src/ipc/extensionServer.ts index 9482ca3..366feca 100644 --- a/src/ipc/extensionServer.ts +++ b/src/ipc/extensionServer.ts @@ -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 (>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 (>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; } @@ -60,7 +46,7 @@ export class ExtensionServer { public getInitSettings(): Promise { let tnsPath = Services.workspaceConfigService().tnsPath; - return Promise.resolve({ tnsPath: tnsPath }); + return Promise.resolve({tnsPath: tnsPath}); } public analyticsLaunchDebugger(args: extProtocol.AnalyticsLaunchDebuggerArgs): Promise { @@ -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) { @@ -125,7 +111,7 @@ 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; @@ -133,21 +119,20 @@ export class ExtensionServer { // no matter what happens, don't break return new Array<{ id: string, name: string }>(); } - } + } private getProvisioningProfileValue(name: string, text: string): string { - let findStr = "" + name + ""; - let index = text.indexOf(findStr); - if (index > 0) { - index = text.indexOf("", index + findStr.length); - if (index > 0) { - index += "".length; - let endIndex = text.indexOf("", index); - let result = text.substring(index, endIndex); - return result; - } - } - - return null; - } + let findStr = "" + name + ""; + let index = text.indexOf(findStr); + if (index > 0) { + index = text.indexOf("", index + findStr.length); + if (index > 0) { + index += "".length; + let endIndex = text.indexOf("", index); + let result = text.substring(index, endIndex); + return result; + } + } + return null; + } } \ No newline at end of file diff --git a/src/ipc/sockedId.ts b/src/ipc/sockedId.ts new file mode 100644 index 0000000..54328e3 --- /dev/null +++ b/src/ipc/sockedId.ts @@ -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'; +} \ No newline at end of file diff --git a/src/tests/nsDebugClient.ts b/src/tests/nsDebugClient.ts index 52f53f5..57581f4 100644 --- a/src/tests/nsDebugClient.ts +++ b/src/tests/nsDebugClient.ts @@ -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 { return this.setBreakpointsRequest({ lines: breakpoints.map(b => b.line), breakpoints: breakpoints, diff --git a/src/tsconfig.json b/src/tsconfig.json index dfdeb1d..624fcdd 100644 --- a/src/tsconfig.json +++ b/src/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "target": "es5", + "target": "es6", "module": "commonjs", "moduleResolution": "node", "sourceMap": true, @@ -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",