Skip to content

Commit e913485

Browse files
authored
Merge pull request #159 from EddyVerbruggen/fix-vscode-1.20-debugging
Fix vscode 1.20 debugging
2 parents e4b89dc + 0e39bfb commit e913485

File tree

4 files changed

+56
-66
lines changed

4 files changed

+56
-66
lines changed

src/debug-adapter/webKitDebugAdapter.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import {DebugProtocol} from 'vscode-debugprotocol';
1010
import {INSDebugConnection} from './connection/INSDebugConnection';
1111
import {IosConnection} from './connection/iosConnection';
1212
import {AndroidConnection} from './connection/androidConnection';
13-
import {Project, DebugResult} from '../project/project';
14-
import {IosProject} from '../project/iosProject';
15-
import {AndroidProject} from '../project/androidProject';
13+
import {DebugResult} from '../project/project';
1614
import * as utils from '../common/utilities';
1715
import {formatConsoleMessage} from './consoleHelper';
1816
import {Services} from '../services/debugAdapterServices';
@@ -129,8 +127,8 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
129127
if (args.tnsOutput) {
130128
Services.logger().addHandler(Handlers.createStreamHandler(fs.createWriteStream(args.tnsOutput)));
131129
}
132-
Services.logger().log(`initialize(${JSON.stringify(this._initArgs) })`);
133-
Services.logger().log(`${args.request}(${JSON.stringify(args)})`);
130+
Services.logger().log(`initialize(${JSON.stringify(this._initArgs) })\n`);
131+
Services.logger().log(`${args.request}(${JSON.stringify(args)})\n`);
134132
}
135133

136134
private async processRequest(args: DebugProtocol.IRequestArgs) {

src/ipc/extensionClient.ts

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,41 @@
1-
import * as path from 'path';
2-
import * as os from 'os';
3-
import * as crypto from 'crypto';
41
import * as extProtocol from './extensionProtocol';
5-
let ipc = require('node-ipc');
2+
import {Services} from "../services/debugAdapterServices";
3+
import {getSocketId} from "./sockedId";
4+
5+
const ipc = require('node-ipc');
66

77
export class ExtensionClient {
88
private _appRoot: string;
99
private _idCounter = 0;
1010
private _pendingRequests: Object;
11+
private _socketId: string;
1112

1213
private _ipcClientInitialized: Promise<any>;
1314

14-
public static getTempFilePathForDirectory(directoryPath: string) {
15-
let fileName: string = 'vsc-ns-ext-' + crypto.createHash('md5').update(directoryPath).digest("hex") + '.sock';
16-
return path.join(os.tmpdir(), fileName);
17-
}
18-
1915
constructor(appRoot: string) {
2016
this._appRoot = appRoot;
2117
this._idCounter = 0;
2218
this._pendingRequests = {};
2319

24-
ipc.config.id = 'debug-adpater-' + process.pid;
20+
this._socketId = getSocketId();
21+
22+
ipc.config.id = 'debug-adapter-' + process.pid;
2523
ipc.config.retry = 1500;
24+
ipc.config.maxRetries = 5;
2625

2726
this._ipcClientInitialized = new Promise((res, rej) => {
2827
ipc.connectTo(
29-
'extHost',
30-
ExtensionClient.getTempFilePathForDirectory(this._appRoot),
28+
this._socketId,
3129
() => {
32-
ipc.of.extHost.on('connect', () => {
30+
ipc.of[this._socketId].on('connect', () => {
3331
res();
3432
});
35-
ipc.of.extHost.on('extension-protocol-message', (response: extProtocol.Response) => {
33+
34+
ipc.of[this._socketId].on('error', error => {
35+
Services.logger().log(`[ExtensionClient] error: ${JSON.stringify(error)}\n`);
36+
});
37+
38+
ipc.of[this._socketId].on('extension-protocol-message', (response: extProtocol.Response) => {
3639
(<(result: Object) => void>this._pendingRequests[response.requestId])(response.result);
3740
});
3841
}
@@ -41,10 +44,10 @@ export class ExtensionClient {
4144
}
4245

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

src/ipc/extensionServer.ts

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,34 @@
11
import * as path from 'path';
2-
import * as os from 'os';
32
import * as fs from 'fs';
4-
import * as crypto from 'crypto';
53
import * as vscode from 'vscode';
4+
import {QuickPickItem} from 'vscode';
65
import * as extProtocol from './extensionProtocol';
76
import {Services} from '../services/extensionHostServices';
8-
import {QuickPickItem} from "vscode";
7+
import {getSocketId} from "./sockedId";
8+
99
let ipc = require('node-ipc');
1010

1111
export class ExtensionServer {
1212
private _isRunning: boolean;
1313

14-
public static getTempFilePathForDirectory(directoryPath: string) {
15-
let fileName: string = 'vsc-ns-ext-' + crypto.createHash('md5').update(directoryPath).digest("hex") + '.sock';
16-
return path.join(os.tmpdir(), fileName);
17-
}
18-
1914
constructor() {
2015
this._isRunning = false;
2116
}
2217

23-
public getPipeHandlePath(): string {
24-
return vscode.workspace.rootPath ?
25-
ExtensionServer.getTempFilePathForDirectory(vscode.workspace.rootPath) :
26-
null;
27-
}
28-
2918
public start() {
3019
if (!this._isRunning) {
31-
let pipeHandlePath = this.getPipeHandlePath();
32-
if (pipeHandlePath) {
33-
ipc.serve(
34-
pipeHandlePath,
35-
() => {
36-
ipc.server.on('extension-protocol-message', (data: extProtocol.Request, socket) => {
37-
return (<Promise<Object>>this[data.method].call(this, data.args)).then(result => {
38-
let response: extProtocol.Response = { requestId: data.id, result: result };
39-
return ipc.server.emit(socket, 'extension-protocol-message', response);
40-
});
20+
ipc.config.id = getSocketId();
21+
ipc.serve(
22+
() => {
23+
ipc.server.on('extension-protocol-message', (data: extProtocol.Request, socket) => {
24+
return (<Promise<Object>>this[data.method].call(this, data.args)).then(result => {
25+
let response: extProtocol.Response = {requestId: data.id, result: result};
26+
return ipc.server.emit(socket, 'extension-protocol-message', response);
4127
});
4228
});
43-
ipc.server.start();
44-
this._isRunning = true;
45-
}
29+
});
30+
ipc.server.start();
31+
this._isRunning = true;
4632
}
4733
return this._isRunning;
4834
}
@@ -60,7 +46,7 @@ export class ExtensionServer {
6046

6147
public getInitSettings(): Promise<extProtocol.InitSettingsResult> {
6248
let tnsPath = Services.workspaceConfigService().tnsPath;
63-
return Promise.resolve({ tnsPath: tnsPath });
49+
return Promise.resolve({tnsPath: tnsPath});
6450
}
6551

6652
public analyticsLaunchDebugger(args: extProtocol.AnalyticsLaunchDebuggerArgs): Promise<any> {
@@ -115,7 +101,7 @@ export class ExtensionServer {
115101
let teamIds: any = {};
116102
for (let file of files) {
117103
let filePath = path.join(dir, file);
118-
let data = fs.readFileSync(filePath, { encoding: "utf8" });
104+
let data = fs.readFileSync(filePath, {encoding: "utf8"});
119105
let teamId = this.getProvisioningProfileValue("TeamIdentifier", data);
120106
let teamName = this.getProvisioningProfileValue("TeamName", data);
121107
if (teamId) {
@@ -125,29 +111,28 @@ export class ExtensionServer {
125111

126112
let teamIdsArray = new Array<{ id: string, name: string }>();
127113
for (let teamId in teamIds) {
128-
teamIdsArray.push({ id: teamId, name: teamIds[teamId] });
114+
teamIdsArray.push({id: teamId, name: teamIds[teamId]});
129115
}
130116

131117
return teamIdsArray;
132118
} catch (e) {
133119
// no matter what happens, don't break
134120
return new Array<{ id: string, name: string }>();
135121
}
136-
}
122+
}
137123

138124
private getProvisioningProfileValue(name: string, text: string): string {
139-
let findStr = "<key>" + name + "</key>";
140-
let index = text.indexOf(findStr);
141-
if (index > 0) {
142-
index = text.indexOf("<string>", index + findStr.length);
143-
if (index > 0) {
144-
index += "<string>".length;
145-
let endIndex = text.indexOf("</string>", index);
146-
let result = text.substring(index, endIndex);
147-
return result;
148-
}
149-
}
150-
151-
return null;
152-
}
125+
let findStr = "<key>" + name + "</key>";
126+
let index = text.indexOf(findStr);
127+
if (index > 0) {
128+
index = text.indexOf("<string>", index + findStr.length);
129+
if (index > 0) {
130+
index += "<string>".length;
131+
let endIndex = text.indexOf("</string>", index);
132+
let result = text.substring(index, endIndex);
133+
return result;
134+
}
135+
}
136+
return null;
137+
}
153138
}

src/ipc/sockedId.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export function getSocketId(): string {
2+
// let's KISS for now - I doubt users will want to simultaneously debug 2 apps anyway
3+
return 'vs-ns-ext';
4+
}

0 commit comments

Comments
 (0)