@@ -54,6 +54,7 @@ import { registerRazorCommands } from './razorCommands';
54
54
import { registerOnAutoInsert } from './onAutoInsert' ;
55
55
import { commonOptions , languageServerOptions , omnisharpOptions } from '../shared/options' ;
56
56
import { NamedPipeInformation } from './roslynProtocol' ;
57
+ import { IDisposable } from '../disposable' ;
57
58
58
59
let _channel : vscode . OutputChannel ;
59
60
let _traceChannel : vscode . OutputChannel ;
@@ -615,23 +616,69 @@ export class RoslynLanguageServer {
615
616
) ;
616
617
}
617
618
619
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
620
+ private WaitForAttachCompleteAsync ( attachRequestId : string ) : Promise < boolean > {
621
+ return new Promise < boolean > ( ( resolve ) => {
622
+ let didTerminateRegistation : IDisposable | null = null ;
623
+ let customEventReg : IDisposable | null = null ;
624
+ let isComplete = false ;
625
+
626
+ const fire = ( result : boolean ) => {
627
+ if ( isComplete === false ) {
628
+ isComplete = true ;
629
+ didTerminateRegistation ?. dispose ( ) ;
630
+ customEventReg ?. dispose ( ) ;
631
+ resolve ( result ) ;
632
+ }
633
+ } ;
634
+
635
+ didTerminateRegistation = vscode . debug . onDidTerminateDebugSession ( ( session : vscode . DebugSession ) => {
636
+ if ( session . configuration . attachRequestId !== attachRequestId ) {
637
+ return ;
638
+ }
639
+
640
+ fire ( false ) ;
641
+ } ) ;
642
+
643
+ customEventReg = vscode . debug . onDidReceiveDebugSessionCustomEvent (
644
+ ( event : vscode . DebugSessionCustomEvent ) => {
645
+ if ( event . session . configuration . attachRequestId !== attachRequestId ) {
646
+ return ;
647
+ }
648
+
649
+ if ( event . event !== 'attachComplete' ) {
650
+ return ;
651
+ }
652
+
653
+ fire ( true ) ;
654
+ }
655
+ ) ;
656
+ } ) ;
657
+ }
658
+
618
659
private registerDebuggerAttach ( ) {
619
660
this . _languageClient . onRequest < RoslynProtocol . DebugAttachParams , RoslynProtocol . DebugAttachResult , void > (
620
661
RoslynProtocol . DebugAttachRequest . type ,
621
662
async ( request ) => {
622
663
const debugOptions = commonOptions . unitTestDebuggingOptions ;
623
664
const debugConfiguration : vscode . DebugConfiguration = {
624
665
...debugOptions ,
625
- name : '.NET Core Attach ' ,
666
+ name : '.NET Debug Unit test ' ,
626
667
type : 'coreclr' ,
627
668
request : 'attach' ,
628
669
processId : request . processId ,
670
+ attachRequestId : randomUUID ( ) ,
629
671
} ;
630
672
631
- const result = await vscode . debug . startDebugging ( undefined , debugConfiguration , undefined ) ;
632
- return {
633
- didAttach : result ,
634
- } ;
673
+ const waitCompletePromise = this . WaitForAttachCompleteAsync ( debugConfiguration . attachRequestId ) ;
674
+
675
+ let success = await vscode . debug . startDebugging ( undefined , debugConfiguration , undefined ) ;
676
+ if ( ! success ) {
677
+ return { didAttach : false } ;
678
+ }
679
+
680
+ success = await waitCompletePromise ;
681
+ return { didAttach : success } ;
635
682
}
636
683
) ;
637
684
}
0 commit comments