Skip to content

Commit 9ab4ec2

Browse files
committed
Fix tests
1 parent f6bc3e2 commit 9ab4ec2

File tree

3 files changed

+117
-199
lines changed

3 files changed

+117
-199
lines changed

src/debug-adapter/nativeScriptDebug.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import * as os from 'os';
22
import * as path from 'path';
33
import { chromeConnection, ChromeDebugSession } from 'vscode-chrome-debug-core';
4-
import { AndroidProject } from '../project/androidProject';
5-
import { IosProject } from '../project/iosProject';
6-
import { NativeScriptCli } from '../project/nativeScriptCli';
7-
import { nativeScriptDebugAdapterGenerator } from './nativeScriptDebugAdapter';
4+
import { NativeScriptDebugAdapter } from './nativeScriptDebugAdapter';
85
import { NativeScriptPathTransformer } from './nativeScriptPathTransformer';
96
import { NativeScriptTargetDiscovery } from './nativeScriptTargetDiscovery';
107

@@ -16,7 +13,7 @@ class NSAndroidConnection extends chromeConnection.ChromeConnection {
1613

1714
ChromeDebugSession.run(ChromeDebugSession.getSession(
1815
{
19-
adapter: nativeScriptDebugAdapterGenerator(IosProject, AndroidProject, NativeScriptCli),
16+
adapter: NativeScriptDebugAdapter,
2017
chromeConnection: NSAndroidConnection,
2118
extensionName: 'nativescript-extension',
2219
logFilePath: path.join(os.tmpdir(), 'nativescript-extension.txt'),
Lines changed: 103 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,138 @@
1-
import { ChromeDebugAdapter, IRestartRequestArgs, logger } from 'vscode-chrome-debug-core';
1+
import { ChromeDebugAdapter, IRestartRequestArgs } from 'vscode-chrome-debug-core';
22
import { Event, TerminatedEvent } from 'vscode-debugadapter';
33
import { DebugProtocol } from 'vscode-debugprotocol';
44
import * as extProtocol from '../common/extensionProtocol';
5-
import { AndroidProject } from '../project/androidProject';
6-
import { IosProject } from '../project/iosProject';
7-
import { NativeScriptCli } from '../project/nativeScriptCli';
85

96
const reconnectAfterLiveSyncTimeout = 10 * 1000;
107

11-
export function nativeScriptDebugAdapterGenerator(iosProject: typeof IosProject,
12-
androidProject: typeof AndroidProject,
13-
nativeScriptCli: typeof NativeScriptCli) {
14-
return class NativeScriptDebugAdapter extends ChromeDebugAdapter {
15-
private _idCounter = 0;
16-
private _pendingRequests: object = {};
17-
private isLiveSync: boolean = false;
18-
private portWaitingResolve: any;
19-
private isDisconnecting: boolean = false;
20-
21-
public attach(args: any): Promise<void> {
22-
return this.processRequestAndAttach(args);
8+
export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
9+
private _idCounter = 0;
10+
private _pendingRequests: object = {};
11+
private isLiveSync: boolean = false;
12+
private portWaitingResolve: any;
13+
private isDisconnecting: boolean = false;
14+
15+
public attach(args: any): Promise<void> {
16+
return this.processRequestAndAttach(args);
17+
}
18+
19+
public launch(args: any): Promise<void> {
20+
return this.processRequestAndAttach(args);
21+
}
22+
23+
public onPortReceived(port) {
24+
this.portWaitingResolve && this.portWaitingResolve(port);
25+
}
26+
27+
public onExtensionResponse(response) {
28+
this._pendingRequests[response.requestId](response.result);
29+
delete this._pendingRequests[response.requestId];
30+
}
31+
32+
public disconnect(args: any): void {
33+
this.isDisconnecting = true;
34+
if (!args.restart) {
35+
this.callRemoteMethod('buildService', 'disconnect');
2336
}
2437

25-
public launch(args: any): Promise<void> {
26-
return this.processRequestAndAttach(args);
27-
}
38+
super.disconnect(args);
39+
}
2840

29-
public onPortReceived(port) {
30-
this.portWaitingResolve && this.portWaitingResolve(port);
31-
}
41+
protected async terminateSession(reason: string, disconnectArgs?: DebugProtocol.DisconnectArguments, restart?: IRestartRequestArgs): Promise<void> {
42+
let restartRequestArgs;
43+
let timeoutId;
3244

33-
public onExtensionResponse(response) {
34-
this._pendingRequests[response.requestId](response.result);
35-
delete this._pendingRequests[response.requestId];
36-
}
45+
if (!this.isDisconnecting && this.isLiveSync) {
46+
const portProm = new Promise<any>((res, rej) => {
47+
this.portWaitingResolve = res;
3748

38-
public disconnect(args: any): void {
39-
this.isDisconnecting = true;
40-
if (!args.restart) {
41-
this.callRemoteMethod('buildService', 'disconnect');
42-
}
49+
timeoutId = setTimeout(() => {
50+
res();
51+
}, reconnectAfterLiveSyncTimeout);
52+
});
4353

44-
super.disconnect(args);
54+
restartRequestArgs = await portProm;
55+
clearTimeout(timeoutId);
4556
}
4657

47-
protected async terminateSession(reason: string, disconnectArgs?: DebugProtocol.DisconnectArguments, restart?: IRestartRequestArgs): Promise<void> {
48-
let restartRequestArgs;
49-
let timeoutId;
58+
await super.terminateSession(reason, disconnectArgs, restartRequestArgs);
59+
}
60+
61+
protected hookConnectionEvents(): void {
62+
super.hookConnectionEvents();
5063

51-
if (!this.isDisconnecting && this.isLiveSync) {
52-
const portProm = new Promise<any>((res, rej) => {
53-
this.portWaitingResolve = res;
64+
this.chrome.Log.onEntryAdded((params) => this.onEntryAdded(params));
65+
}
5466

55-
timeoutId = setTimeout(() => {
56-
res();
57-
}, reconnectAfterLiveSyncTimeout);
58-
});
67+
protected onEntryAdded(params: any): void {
68+
if (params && params.entry && params.entry.level) {
69+
const message = params.entry;
5970

60-
restartRequestArgs = await portProm;
61-
clearTimeout(timeoutId);
71+
message.type = message.level;
72+
73+
const that = this as any;
74+
const script = that.getScriptByUrl && that.getScriptByUrl(params.entry.url);
75+
76+
if (script) {
77+
message.stack = {
78+
callFrames: [
79+
{
80+
columnNumber: 0,
81+
lineNumber: params.entry.lineNumber,
82+
scriptId: script.scriptId,
83+
url: params.entry.url,
84+
},
85+
],
86+
};
6287
}
6388

64-
await super.terminateSession(reason, disconnectArgs, restartRequestArgs);
89+
this.onMessageAdded({
90+
message,
91+
});
6592
}
93+
}
6694

67-
protected hookConnectionEvents(): void {
68-
super.hookConnectionEvents();
95+
private async processRequestAndAttach(args: any) {
96+
const transformedArgs = this.translateArgs(args);
6997

70-
this.chrome.Log.onEntryAdded((params) => this.onEntryAdded(params));
98+
if (args.__restart) {
99+
transformedArgs.port = args.__restart.port;
100+
} else {
101+
this._session.sendEvent(new Event(extProtocol.BEFORE_DEBUG_START));
102+
transformedArgs.port = await this.callRemoteMethod('buildService', 'processRequest', transformedArgs);
71103
}
72104

73-
protected onEntryAdded(params: any): void {
74-
if (params && params.entry && params.entry.level) {
75-
const message = params.entry;
76-
77-
message.type = message.level;
78-
79-
const that = this as any;
80-
const script = that.getScriptByUrl && that.getScriptByUrl(params.entry.url);
81-
82-
if (script) {
83-
message.stack = {
84-
callFrames: [
85-
{
86-
columnNumber: 0,
87-
lineNumber: params.entry.lineNumber,
88-
scriptId: script.scriptId,
89-
url: params.entry.url,
90-
},
91-
],
92-
};
93-
}
94-
95-
this.onMessageAdded({
96-
message,
97-
});
98-
}
105+
if (!transformedArgs.port) {
106+
this._session.sendEvent(new TerminatedEvent());
99107
}
100108

101-
private async processRequestAndAttach(args: any) {
102-
const transformedArgs = this.translateArgs(args);
109+
(this.pathTransformer as any).setTargetPlatform(args.platform);
110+
(ChromeDebugAdapter as any).SET_BREAKPOINTS_TIMEOUT = 20000;
103111

104-
if (args.__restart) {
105-
transformedArgs.port = args.__restart.port;
106-
} else {
107-
this._session.sendEvent(new Event(extProtocol.BEFORE_DEBUG_START));
108-
transformedArgs.port = await this.callRemoteMethod('buildService', 'processRequest', transformedArgs);
109-
}
112+
this.isLiveSync = args.watch;
110113

111-
if (!transformedArgs.port) {
112-
this._session.sendEvent(new TerminatedEvent());
113-
}
114-
115-
(this.pathTransformer as any).setTargetPlatform(args.platform);
116-
(ChromeDebugAdapter as any).SET_BREAKPOINTS_TIMEOUT = 20000;
117-
118-
this.isLiveSync = args.watch;
114+
return super.attach(transformedArgs);
115+
}
119116

120-
return super.attach(transformedArgs);
117+
private translateArgs(args): any {
118+
if (args.diagnosticLogging) {
119+
args.trace = args.diagnosticLogging;
121120
}
122121

123-
private translateArgs(args): any {
124-
if (args.diagnosticLogging) {
125-
args.trace = args.diagnosticLogging;
126-
}
127-
128-
if (args.appRoot) {
129-
args.webRoot = args.appRoot;
130-
}
131-
132-
return args;
122+
if (args.appRoot) {
123+
args.webRoot = args.appRoot;
133124
}
134125

135-
private callRemoteMethod<T>(service: string, method: string, ...args: any[]): Promise<T> {
136-
const request: extProtocol.IRequest = { id: `req${++this._idCounter}`, service, method, args };
126+
return args;
127+
}
137128

138-
return new Promise<T>((res, rej) => {
139-
this._pendingRequests[request.id] = res;
129+
private callRemoteMethod<T>(service: string, method: string, ...args: any[]): Promise<T> {
130+
const request: extProtocol.IRequest = { id: `req${++this._idCounter}`, service, method, args };
140131

141-
this._session.sendEvent(new Event(extProtocol.NS_DEBUG_ADAPTER_MESSAGE, request));
142-
});
143-
}
144-
};
145-
}
132+
return new Promise<T>((res, rej) => {
133+
this._pendingRequests[request.id] = res;
134+
135+
this._session.sendEvent(new Event(extProtocol.NS_DEBUG_ADAPTER_MESSAGE, request));
136+
});
137+
}
138+
};

0 commit comments

Comments
 (0)