@@ -426,6 +426,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
426
426
this . logger . writeVerbose ( `Dotnet attach debug configuration: ${ JSON . stringify ( dotnetAttachConfig , undefined , 2 ) } ` ) ;
427
427
this . logger . writeVerbose ( `Attached dotnet debugger to process: ${ pid } ` ) ;
428
428
}
429
+
429
430
return this . tempSessionDetails ;
430
431
}
431
432
@@ -452,7 +453,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
452
453
} ;
453
454
}
454
455
455
- /** Fetches all available vscode launch configurations. This is abstracted out for easier testing */
456
+ /** Fetches all available vscode launch configurations. This is abstracted out for easier testing. */
456
457
private getLaunchConfigurations ( ) : DebugConfiguration [ ] {
457
458
return workspace . getConfiguration ( "launch" ) . get < DebugConfiguration [ ] > ( "configurations" ) ?? [ ] ;
458
459
}
@@ -471,6 +472,10 @@ export class DebugSessionFeature extends LanguageClientConsumer
471
472
return PREVENT_DEBUG_START ;
472
473
}
473
474
475
+ if ( config . processId === 0 || config . processId === "current" ) {
476
+ config . processId = await this . sessionManager . getLanguageServerPid ( ) ;
477
+ }
478
+
474
479
// If nothing is set, prompt for the processId.
475
480
if ( ! config . customPipeName && ! config . processId ) {
476
481
config . processId = await commands . executeCommand ( "PowerShell.PickPSHostProcess" ) ;
@@ -528,12 +533,13 @@ export class SpecifyScriptArgsFeature implements Disposable {
528
533
if ( text !== undefined ) {
529
534
await this . context . workspaceState . update ( powerShellDbgScriptArgsKey , text ) ;
530
535
}
536
+
531
537
return text ;
532
538
}
533
539
}
534
540
535
541
interface IProcessItem extends QuickPickItem {
536
- pid : string ; // payload for the QuickPick UI
542
+ processId : number ; // payload for the QuickPick UI
537
543
}
538
544
539
545
// eslint-disable-next-line @typescript-eslint/no-empty-interface
@@ -542,7 +548,7 @@ interface IGetPSHostProcessesArguments {
542
548
543
549
interface IPSHostProcessInfo {
544
550
processName : string ;
545
- processId : string ;
551
+ processId : number ;
546
552
appDomainName : string ;
547
553
mainWindowTitle : string ;
548
554
}
@@ -551,19 +557,16 @@ export const GetPSHostProcessesRequestType =
551
557
new RequestType < IGetPSHostProcessesArguments , IPSHostProcessInfo [ ] , string > ( "powerShell/getPSHostProcesses" ) ;
552
558
553
559
export class PickPSHostProcessFeature extends LanguageClientConsumer {
554
-
555
560
private command : Disposable ;
556
561
private waitingForClientToken ?: CancellationTokenSource ;
557
562
private getLanguageClientResolve ?: ( value : LanguageClient ) => void ;
558
563
559
564
constructor ( private logger : ILogger ) {
560
565
super ( ) ;
561
566
562
- this . command =
563
- commands . registerCommand ( "PowerShell.PickPSHostProcess" , ( ) => {
564
- return this . getLanguageClient ( )
565
- . then ( ( _ ) => this . pickPSHostProcess ( ) , ( _ ) => undefined ) ;
566
- } ) ;
567
+ this . command = commands . registerCommand ( "PowerShell.PickPSHostProcess" , async ( ) => {
568
+ return this . pickPSHostProcess ( ) ;
569
+ } ) ;
567
570
}
568
571
569
572
public override setLanguageClient ( languageClient : LanguageClient ) : void {
@@ -617,25 +620,24 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
617
620
}
618
621
}
619
622
620
- private async pickPSHostProcess ( ) : Promise < string | undefined > {
623
+ private async pickPSHostProcess ( ) : Promise < number | undefined > {
624
+ // We need the language client in order to send the request.
625
+ await this . getLanguageClient ( ) ;
626
+
621
627
// Start with the current PowerShell process in the list.
622
- const items : IProcessItem [ ] = [ {
623
- label : "Current" ,
624
- description : "The current PowerShell Extension process." ,
625
- pid : "current" ,
626
- } ] ;
628
+ const items : IProcessItem [ ] = [ ] ;
627
629
628
630
const response = await this . languageClient ?. sendRequest ( GetPSHostProcessesRequestType , { } ) ;
629
631
for ( const process of response ?? [ ] ) {
630
632
let windowTitle = "" ;
631
633
if ( process . mainWindowTitle ) {
632
- windowTitle = `, Title: ${ process . mainWindowTitle } ` ;
634
+ windowTitle = `, ${ process . mainWindowTitle } ` ;
633
635
}
634
636
635
637
items . push ( {
636
638
label : process . processName ,
637
639
description : `PID: ${ process . processId . toString ( ) } ${ windowTitle } ` ,
638
- pid : process . processId ,
640
+ processId : process . processId ,
639
641
} ) ;
640
642
}
641
643
@@ -648,9 +650,10 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
648
650
matchOnDescription : true ,
649
651
matchOnDetail : true ,
650
652
} ;
653
+
651
654
const item = await window . showQuickPick ( items , options ) ;
652
655
653
- return item ? item . pid : undefined ;
656
+ return item ?. processId ?? undefined ;
654
657
}
655
658
656
659
private clearWaitingToken ( ) : void {
@@ -660,7 +663,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
660
663
}
661
664
662
665
interface IRunspaceItem extends QuickPickItem {
663
- id : string ; // payload for the QuickPick UI
666
+ id : number ; // payload for the QuickPick UI
664
667
}
665
668
666
669
// eslint-disable-next-line @typescript-eslint/no-empty-interface
@@ -677,18 +680,16 @@ export const GetRunspaceRequestType =
677
680
new RequestType < IGetRunspaceRequestArguments , IRunspace [ ] , string > ( "powerShell/getRunspace" ) ;
678
681
679
682
export class PickRunspaceFeature extends LanguageClientConsumer {
680
-
681
683
private command : Disposable ;
682
684
private waitingForClientToken ?: CancellationTokenSource ;
683
685
private getLanguageClientResolve ?: ( value : LanguageClient ) => void ;
684
686
685
687
constructor ( private logger : ILogger ) {
686
688
super ( ) ;
687
- this . command =
688
- commands . registerCommand ( "PowerShell.PickRunspace" , ( processId ) => {
689
- return this . getLanguageClient ( )
690
- . then ( ( _ ) => this . pickRunspace ( processId ) , ( _ ) => undefined ) ;
691
- } , this ) ;
689
+
690
+ this . command = commands . registerCommand ( "PowerShell.PickRunspace" ,
691
+ async ( processId ) => { return this . pickRunspace ( processId ) ; } ,
692
+ this ) ;
692
693
}
693
694
694
695
public override setLanguageClient ( languageClient : LanguageClient ) : void {
@@ -734,28 +735,26 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
734
735
this . clearWaitingToken ( ) ;
735
736
reject ( ) ;
736
737
737
- void this . logger . writeAndShowError ( "Attach to PowerShell host process: PowerShell session took too long to start." ) ;
738
+ void this . logger . writeAndShowError (
739
+ "Attach to PowerShell host process: PowerShell session took too long to start." ) ;
738
740
}
739
741
} , 60000 ) ;
740
742
} ,
741
743
) ;
742
744
}
743
745
}
744
746
745
- private async pickRunspace ( processId : string ) : Promise < string | undefined > {
747
+ private async pickRunspace ( processId : number ) : Promise < number | undefined > {
748
+ // We need the language client in order to send the request.
749
+ await this . getLanguageClient ( ) ;
750
+
746
751
const response = await this . languageClient ?. sendRequest ( GetRunspaceRequestType , { processId } ) ;
747
752
const items : IRunspaceItem [ ] = [ ] ;
748
753
for ( const runspace of response ?? [ ] ) {
749
- // Skip default runspace
750
- if ( ( runspace . id === 1 || runspace . name === "PSAttachRunspace" )
751
- && processId === "current" ) {
752
- continue ;
753
- }
754
-
755
754
items . push ( {
756
755
label : runspace . name ,
757
756
description : `ID: ${ runspace . id } - ${ runspace . availability } ` ,
758
- id : runspace . id . toString ( ) ,
757
+ id : runspace . id ,
759
758
} ) ;
760
759
}
761
760
@@ -764,9 +763,10 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
764
763
matchOnDescription : true ,
765
764
matchOnDetail : true ,
766
765
} ;
766
+
767
767
const item = await window . showQuickPick ( items , options ) ;
768
768
769
- return item ? item . id : undefined ;
769
+ return item ? .id ?? undefined ;
770
770
}
771
771
772
772
private clearWaitingToken ( ) : void {
0 commit comments