1
- import { IInitializeRequestArgs , ChromeDebugAdapter , IAttachRequestArgs , ISetBreakpointsArgs , ISetBreakpointsResponseBody , ILaunchRequestArgs , ITelemetryPropertyCollector } from 'vscode-chrome-debug-core' ;
2
- import { OutputEvent , TerminatedEvent } from 'vscode-debugadapter' ;
1
+ import { ChromeDebugAdapter } from 'vscode-chrome-debug-core' ;
2
+ import { OutputEvent , TerminatedEvent , Event } from 'vscode-debugadapter' ;
3
3
import * as utils from '../common/utilities' ;
4
4
import { IosProject } from '../project/iosProject' ;
5
5
import { AndroidProject } from '../project/androidProject' ;
6
6
import { ChildProcess } from 'child_process' ;
7
7
import * as fs from 'fs' ;
8
8
import * as path from 'path' ;
9
9
import { DebugResult } from '../project/project' ;
10
- import { Services } from '../services/debugAdapterServices'
10
+ import * as extProtocol from '../common/extensionProtocol' ;
11
+ import { DebugProtocol } from 'vscode-debugprotocol' ;
12
+ import { Logger } from '../common/logger' ;
13
+ import { NativeScriptCli } from '../project/nativeScriptCli' ;
11
14
12
15
export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
13
16
private _tnsProcess : ChildProcess ;
17
+ private _idCounter = 0 ;
18
+ private _pendingRequests : Object = { } ;
14
19
15
20
public async attach ( args : any ) : Promise < void > {
16
21
return await this . processRequestAndAttach ( args ) ;
17
22
}
18
23
19
- public async launch ( args : any , telemetryPropertyCollector ?: ITelemetryPropertyCollector ) : Promise < void > {
24
+ public async launch ( args : any ) : Promise < void > {
20
25
return await this . processRequestAndAttach ( args ) ;
21
26
}
22
27
@@ -39,19 +44,24 @@ export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
39
44
return super . attach ( transformedArgs ) ;
40
45
}
41
46
47
+ public onExtensionResponse ( response ) {
48
+ this . _pendingRequests [ response . requestId ] ( response . result ) ;
49
+ delete this . _pendingRequests [ response . requestId ] ;
50
+ }
51
+
42
52
private async processRequest ( args : any ) : Promise < any > {
43
53
args = this . translateArgs ( args ) ;
44
- Services . appRoot = args . appRoot ;
45
- Services . extensionClient ( ) . cleanBeforeDebug ( ) ;
46
- const settings = await Services . extensionClient ( ) . getInitSettings ( ) ;
47
54
48
- Services . cliPath = settings . tnsPath || Services . cliPath ;
55
+ this . _session . sendEvent ( new Event ( extProtocol . BEFORE_DEBUG_START ) ) ;
56
+
57
+ const tnsPath = await this . callRemoteMethod < string > ( 'workspaceConfigService' , 'tnsPath' ) ;
58
+ const cli = new NativeScriptCli ( tnsPath , new Logger ( ) ) ;
49
59
50
60
const project = args . platform == "ios" ?
51
- new IosProject ( args . appRoot , Services . cli ( ) ) :
52
- new AndroidProject ( args . appRoot , Services . cli ( ) ) ;
61
+ new IosProject ( args . appRoot , cli ) :
62
+ new AndroidProject ( args . appRoot , cli ) ;
53
63
54
- Services . extensionClient ( ) . analyticsLaunchDebugger ( { request : args . request , platform : args . platform } ) ;
64
+ this . callRemoteMethod ( 'analyticsService' , 'launchDebugger' , args . request , args . platform ) ;
55
65
56
66
// Run CLI Command
57
67
this . log ( `[NSDebugAdapter] Using tns CLI v${ project . cli . version . version } on path '${ project . cli . path } '\n` ) ;
@@ -64,9 +74,9 @@ export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
64
74
// For iOS the TeamID is required if there's more than one.
65
75
// Therefore if not set, show selection to the user.
66
76
if ( args . platform && args . platform . toLowerCase ( ) === 'ios' ) {
67
- let teamId = this . getTeamId ( path . join ( Services . appRoot , 'app' ) , tnsArgs ) ;
77
+ let teamId = this . getTeamId ( path . join ( args . appRoot , 'app' ) , tnsArgs ) ;
68
78
if ( ! teamId ) {
69
- let selectedTeam = ( await Services . extensionClient ( ) . selectTeam ( ) ) ;
79
+ let selectedTeam = await this . callRemoteMethod < { id : string , name : string } > ( 'iOSTeamService' , ' selectTeam' ) ;
70
80
if ( selectedTeam ) {
71
81
// add the selected by the user Team Id
72
82
tnsArgs = ( tnsArgs || [ ] ) . concat ( [ '--teamId' , selectedTeam . id ] ) ;
@@ -174,5 +184,15 @@ export class NativeScriptDebugAdapter extends ChromeDebugAdapter {
174
184
175
185
private readTeamId ( appRoot ) : string {
176
186
return this . readXCConfig ( appRoot , "DEVELOPMENT_TEAM" ) ;
177
- }
187
+ }
188
+
189
+ private callRemoteMethod < T > ( service : string , method : string , ...args : any [ ] ) : Promise < T > {
190
+ let request : extProtocol . Request = { id : `req${ ++ this . _idCounter } ` , service : service , method : method , args : args } ;
191
+
192
+ return new Promise < T > ( ( res , rej ) => {
193
+ this . _pendingRequests [ request . id ] = res ;
194
+
195
+ this . _session . sendEvent ( new Event ( extProtocol . NS_DEBUG_ADAPTER_MESSAGE , request ) ) ;
196
+ } ) ;
197
+ }
178
198
}
0 commit comments