@@ -132,7 +132,7 @@ export function debugDotnetTest(testMethod: string, fileName: string, testFramew
132132 let outputChannel = getTestOutputChannel ( ) ;
133133 outputChannel . appendLine ( `Debugging method '${ testMethod } '.` ) ;
134134
135- return serverUtils . requestProjectInformation ( server , { FileName : fileName } )
135+ return serverUtils . requestProjectInformation ( server , { FileName : fileName } )
136136 . then ( projectInfo => {
137137 if ( projectInfo . DotNetProject ) {
138138 debugType = "legacy" ;
@@ -147,9 +147,7 @@ export function debugDotnetTest(testMethod: string, fileName: string, testFramew
147147 throw new Error ( ) ;
148148 }
149149 } )
150- . then ( ( ) => {
151- return getLaunchConfiguration ( server , debugType , fileName , testMethod , testFrameworkName , debugEventListener ) ;
152- } )
150+ . then ( ( ) => getLaunchConfiguration ( server , debugType , fileName , testMethod , testFrameworkName , debugEventListener ) )
153151 . then ( config => vscode . commands . executeCommand ( 'vscode.startDebug' , config ) )
154152 . catch ( reason => {
155153 vscode . window . showErrorMessage ( `Failed to start debugger: ${ reason } ` ) ;
@@ -182,13 +180,13 @@ export function updateCodeLensForTest(bucket: vscode.CodeLens[], fileName: strin
182180}
183181
184182class DebugEventListener {
185- static s_activeInstance : DebugEventListener = null ;
183+ static s_activeInstance : DebugEventListener = null ;
186184 _fileName : string ;
187185 _server : OmniSharpServer ;
188- _outputChannel : vscode . OutputChannel ;
189- _pipePath : string ;
186+ _outputChannel : vscode . OutputChannel ;
187+ _pipePath : string ;
190188
191- _serverSocket : net . Server ;
189+ _serverSocket : net . Server ;
192190 _isClosed : boolean = false ;
193191
194192 constructor ( fileName : string , server : OmniSharpServer , outputChannel : vscode . OutputChannel ) {
@@ -204,38 +202,41 @@ class DebugEventListener {
204202 }
205203 }
206204
207- public start ( ) : Promise < void > {
205+ public start ( ) : Promise < void > {
208206
209207 // We use our process id as part of the pipe name, so if we still somehow have an old instance running, close it.
210208 if ( DebugEventListener . s_activeInstance !== null ) {
211209 DebugEventListener . s_activeInstance . close ( ) ;
212210 }
213211 DebugEventListener . s_activeInstance = this ;
214-
212+
215213 this . _serverSocket = net . createServer ( ( socket : net . Socket ) => {
216214 socket . on ( 'data' , ( buffer : Buffer ) => {
217-
218215 let event : DebuggerEventsProtocol . DebuggerEvent ;
219216 try {
220217 event = DebuggerEventsProtocol . decodePacket ( buffer ) ;
221- } catch ( e ) {
218+ }
219+ catch ( e ) {
222220 this . _outputChannel . appendLine ( "Warning: Invalid event received from debugger" ) ;
223221 return ;
224222 }
225-
226- if ( event . eventType === DebuggerEventsProtocol . EventType . ProcessLaunched ) {
227- let processLaunchedEvent = < DebuggerEventsProtocol . ProcessLaunchedEvent > ( event ) ;
228- this . _outputChannel . appendLine ( `Started debugging process #${ processLaunchedEvent . targetProcessId } .` ) ;
229- // TODO: provide the process id to OmniSharp
230- serverUtils . debugTestRun ( this . _server , { FileName : this . _fileName } ) ;
231- } else if ( event . eventType === DebuggerEventsProtocol . EventType . DebuggingStopped ) {
232- this . _outputChannel . appendLine ( "Debugging complete." ) ;
233- this . fireDebuggingStopped ( ) ;
223+
224+ switch ( event . eventType ) {
225+ case DebuggerEventsProtocol . EventType . ProcessLaunched :
226+ let processLaunchedEvent = < DebuggerEventsProtocol . ProcessLaunchedEvent > ( event ) ;
227+ this . _outputChannel . appendLine ( `Started debugging process #${ processLaunchedEvent . targetProcessId } .` ) ;
228+ this . onProcessLaunched ( processLaunchedEvent . targetProcessId ) ;
229+ break ;
230+
231+ case DebuggerEventsProtocol . EventType . DebuggingStopped :
232+ this . _outputChannel . appendLine ( "Debugging complete.\n" ) ;
233+ this . onDebuggingStopped ( ) ;
234+ break ;
234235 }
235236 } ) ;
236237
237238 socket . on ( 'end' , ( ) => {
238- this . fireDebuggingStopped ( ) ;
239+ this . onDebuggingStopped ( ) ;
239240 } ) ;
240241 } ) ;
241242
@@ -257,39 +258,62 @@ class DebugEventListener {
257258 } ) ;
258259 }
259260
260- public pipePath ( ) : string {
261+ public pipePath ( ) : string {
261262 return this . _pipePath ;
262263 }
263264
264265 public close ( ) {
265266 if ( this === DebugEventListener . s_activeInstance ) {
266267 DebugEventListener . s_activeInstance = null ;
267268 }
269+
268270 if ( this . _isClosed ) {
269271 return ;
270272 }
273+
271274 this . _isClosed = true ;
272275
273276 if ( this . _serverSocket !== null ) {
274277 this . _serverSocket . close ( ) ;
275278 }
276279 }
277280
278- private fireDebuggingStopped ( ) : void {
281+ private onProcessLaunched ( targetProcessId : number ) : void {
282+ let request : protocol . V2 . DebugTestLaunchRequest = {
283+ FileName : this . _fileName ,
284+ TargetProcessId : targetProcessId
285+ } ;
286+
287+ const disposable = this . _server . onTestMessage ( e => {
288+ this . _outputChannel . appendLine ( e . Message ) ;
289+ } ) ;
290+
291+ serverUtils . debugTestLaunch ( this . _server , request )
292+ . then ( _ => {
293+ disposable . dispose ( ) ;
294+ } ) ;
295+ }
296+
297+ private onDebuggingStopped ( ) : void {
279298 if ( this . _isClosed ) {
280299 return ;
281300 }
282-
283- // TODO: notify omniSharp
301+
302+ let request : protocol . V2 . DebugTestStopRequest = {
303+ FileName : this . _fileName
304+ } ;
305+
306+ serverUtils . debugTestStop ( this . _server , request ) ;
284307
285308 this . close ( ) ;
286309 }
287310
288- private removeSocketFileIfExists ( ) : Promise < void > {
311+ private removeSocketFileIfExists ( ) : Promise < void > {
289312 if ( os . platform ( ) === 'win32' ) {
290313 // Win32 doesn't use the file system for pipe names
291314 return Promise . resolve ( ) ;
292- } else {
315+ }
316+ else {
293317 return utils . deleteIfExists ( this . _pipePath ) ;
294318 }
295319 }
0 commit comments