@@ -17,6 +17,7 @@ import * as ns from '../services/NsCliService';
17
17
import { AnalyticsService } from '../services/analytics/AnalyticsService' ;
18
18
import { ExtensionClient } from '../services/ipc/ExtensionClient' ;
19
19
import { Logger , LoggerHandler , Handlers , Tags } from '../services/Logger' ;
20
+ import { DebugConfiguration } from './debugConfiguration' ;
20
21
21
22
interface IScopeVarHandle {
22
23
objectId : string ;
@@ -42,6 +43,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
42
43
private platform : string ;
43
44
private _lastOutputEvent : OutputEvent ;
44
45
private _loggerFrontendHandler : LoggerHandler = args => this . fireEvent ( new OutputEvent ( ` ›${ args . message } \n` , args . type . toString ( ) ) ) ;
46
+ private _debugConfig : DebugConfiguration ;
45
47
46
48
public constructor ( ) {
47
49
this . _variableHandles = new Handles < IScopeVarHandle > ( ) ;
@@ -100,14 +102,15 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
100
102
}
101
103
102
104
public launch ( args : DebugProtocol . ILaunchRequestArgs ) : Promise < void > {
103
- return this . _attach ( args ) ;
105
+ return this . processRequest ( args ) ;
104
106
}
105
107
106
108
public attach ( args : DebugProtocol . IAttachRequestArgs ) : Promise < void > {
107
- return this . _attach ( args ) ;
109
+ return this . processRequest ( args ) ;
108
110
}
109
111
110
- private configureLoggingForRequest ( name : string , args : DebugProtocol . IAttachRequestArgs | DebugProtocol . ILaunchRequestArgs ) : void {
112
+ private configureLoggingForRequest ( ) : void {
113
+ let args = this . _debugConfig . args ;
111
114
if ( args . diagnosticLogging ) {
112
115
// The logger frontend handler is initially configured to handle messages with LoggerTagFrontendMessage tag only.
113
116
// We remove the handler and add it again for all messages.
@@ -118,18 +121,19 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
118
121
Logger . addHandler ( Handlers . createStreamHandler ( fs . createWriteStream ( args . tnsOutput ) ) ) ;
119
122
}
120
123
Logger . log ( `initialize(${ JSON . stringify ( this . _initArgs ) } )` ) ;
121
- Logger . log ( `${ name } (${ JSON . stringify ( args ) } )` ) ;
124
+ Logger . log ( `${ this . _debugConfig . args . request } (${ JSON . stringify ( this . _debugConfig . isAttach ? this . _debugConfig . attachArgs : this . _debugConfig . launchArgs ) } )` ) ;
122
125
}
123
126
124
- private _attach ( args : DebugProtocol . IAttachRequestArgs | DebugProtocol . ILaunchRequestArgs ) {
127
+ private processRequest ( args : DebugProtocol . IRequestArgs ) {
128
+ this . _debugConfig = new DebugConfiguration ( args ) ;
125
129
ExtensionClient . setAppRoot ( args . appRoot ) ;
126
- let analyticsRequest = ( args . request == "launch" && ! ( args as DebugProtocol . ILaunchRequestArgs ) . rebuild ) ? "sync" : args . request ;
130
+ let analyticsRequest = this . _debugConfig . isSync ? "sync" : args . request ;
127
131
ExtensionClient . getInstance ( ) . analyticsLaunchDebugger ( { request : analyticsRequest , platform : args . platform } ) ;
128
- this . configureLoggingForRequest ( args . request , args ) ;
132
+ this . configureLoggingForRequest ( ) ;
129
133
this . appRoot = args . appRoot ;
130
134
this . platform = args . platform ;
131
135
132
- return ( ( args . platform == 'ios' ) ? this . _attachIos ( args ) : this . _attachAndroid ( args ) )
136
+ return ( ( args . platform == 'ios' ) ? this . _attachIos ( ) : this . _attachAndroid ( ) )
133
137
. then ( ( ) => {
134
138
this . fireEvent ( new InitializedEvent ( ) ) ;
135
139
} ,
@@ -140,18 +144,20 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
140
144
} ) ;
141
145
}
142
146
143
- private _attachIos ( args : DebugProtocol . IAttachRequestArgs | DebugProtocol . ILaunchRequestArgs ) : Promise < void > {
147
+ private _attachIos ( ) : Promise < void > {
148
+ let args = this . _debugConfig . args ;
144
149
let iosProject : ns . IosProject = new ns . IosProject ( this . appRoot , args . tnsOutput ) ;
145
150
146
151
return iosProject . debug ( args )
147
152
. then ( ( socketFilePath ) => {
148
153
let iosConnection : IosConnection = new IosConnection ( ) ;
149
- this . setConnection ( iosConnection , args ) ;
154
+ this . setConnection ( iosConnection ) ;
150
155
return iosConnection . attach ( socketFilePath ) ;
151
156
} ) ;
152
157
}
153
158
154
- private _attachAndroid ( args : DebugProtocol . IAttachRequestArgs | DebugProtocol . ILaunchRequestArgs ) : Promise < void > {
159
+ private _attachAndroid ( ) : Promise < void > {
160
+ let args = this . _debugConfig . args ;
155
161
let androidProject : ns . AndroidProject = new ns . AndroidProject ( this . appRoot , args . tnsOutput ) ;
156
162
let thisAdapter : WebKitDebugAdapter = this ;
157
163
@@ -166,7 +172,7 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
166
172
port = debugPort ;
167
173
if ( ! thisAdapter . _webKitConnection ) {
168
174
androidConnection = new AndroidConnection ( ) ;
169
- this . setConnection ( androidConnection , args ) ;
175
+ this . setConnection ( androidConnection ) ;
170
176
}
171
177
} ) . then ( ( ) => {
172
178
Logger . log ( "Attaching to debug application" ) ;
@@ -175,7 +181,8 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
175
181
} ) ;
176
182
}
177
183
178
- private setConnection ( connection : INSDebugConnection , args : DebugProtocol . IAttachRequestArgs | DebugProtocol . ILaunchRequestArgs ) : INSDebugConnection {
184
+ private setConnection ( connection : INSDebugConnection ) : INSDebugConnection {
185
+ let args = this . _debugConfig . args ;
179
186
connection . on ( 'Debugger.paused' , params => this . onDebuggerPaused ( params ) ) ;
180
187
connection . on ( 'Debugger.resumed' , ( ) => this . onDebuggerResumed ( ) ) ;
181
188
connection . on ( 'Debugger.scriptParsed' , params => this . onScriptParsed ( params ) ) ;
@@ -186,12 +193,12 @@ export class WebKitDebugAdapter implements DebugProtocol.IDebugAdapter {
186
193
connection . on ( 'Inspector.detached' , ( ) => this . terminateSession ( ) ) ;
187
194
connection . on ( 'close' , ( ) => this . terminateSession ( ) ) ;
188
195
connection . on ( 'error' , ( ) => this . terminateSession ( ) ) ;
189
- connection . on ( 'connect' , ( ) => this . onConnected ( args ) )
196
+ connection . on ( 'connect' , ( ) => this . onConnected ( ) )
190
197
this . _webKitConnection = connection ;
191
198
return connection ;
192
199
}
193
200
194
- private onConnected ( args : DebugProtocol . IAttachRequestArgs | DebugProtocol . ILaunchRequestArgs ) : void {
201
+ private onConnected ( ) : void {
195
202
Logger . log ( "Debugger connected" ) ;
196
203
}
197
204
0 commit comments