@@ -87,15 +87,14 @@ export const DebugConfigurations: Record<DebugConfig, DebugConfiguration> = {
87
87
name : "PowerShell: Attach to PowerShell Host Process" ,
88
88
type : "PowerShell" ,
89
89
request : "attach" ,
90
- runspaceId : 1 ,
91
90
} ,
92
91
[ DebugConfig . RunPester ] : {
93
92
name : "PowerShell: Run Pester Tests" ,
94
93
type : "PowerShell" ,
95
94
request : "launch" ,
96
95
script : "Invoke-Pester" ,
97
96
createTemporaryIntegratedConsole : true ,
98
- attachDotnetDebugger : true
97
+ attachDotnetDebugger : true ,
99
98
} ,
100
99
[ DebugConfig . ModuleInteractiveSession ] : {
101
100
name : "PowerShell: Module Interactive Session" ,
@@ -109,15 +108,15 @@ export const DebugConfigurations: Record<DebugConfig, DebugConfiguration> = {
109
108
request : "launch" ,
110
109
script : "Enter command to import your binary module, for example: \"Import-Module -Force ${workspaceFolder}/path/to/module.psd1|dll\"" ,
111
110
createTemporaryIntegratedConsole : true ,
112
- attachDotnetDebugger : true
111
+ attachDotnetDebugger : true ,
113
112
} ,
114
113
[ DebugConfig . BinaryModulePester ] : {
115
114
name : "PowerShell: Binary Module Pester Tests" ,
116
115
type : "PowerShell" ,
117
116
request : "launch" ,
118
117
script : "Invoke-Pester" ,
119
118
createTemporaryIntegratedConsole : true ,
120
- attachDotnetDebugger : true
119
+ attachDotnetDebugger : true ,
121
120
}
122
121
} ;
123
122
@@ -131,7 +130,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
131
130
132
131
constructor ( context : ExtensionContext , private sessionManager : SessionManager , private logger : ILogger ) {
133
132
super ( ) ;
134
- // This "activates" the debug adapter for use with You can only do this once.
133
+ // This "activates" the debug adapter. You can only do this once.
135
134
[
136
135
DebugConfigurationProviderTriggerKind . Initial ,
137
136
DebugConfigurationProviderTriggerKind . Dynamic
@@ -276,11 +275,15 @@ export class DebugSessionFeature extends LanguageClientConsumer
276
275
return resolvedConfig ;
277
276
}
278
277
279
- // This is our factory entrypoint hook to when a debug session starts, and where we will lazy initialize everything needed to do the debugging such as a temporary console if required
278
+ // This is our factory entrypoint hook to when a debug session starts, and
279
+ // where we will lazy initialize everything needed to do the debugging such
280
+ // as a temporary console if required.
281
+ //
282
+ // NOTE: A Promise meets the shape of a ProviderResult, which allows us to
283
+ // make this method async.
280
284
public async createDebugAdapterDescriptor (
281
285
session : DebugSession ,
282
286
_executable : DebugAdapterExecutable | undefined ) : Promise < DebugAdapterDescriptor | undefined > {
283
- // NOTE: A Promise meets the shape of a ProviderResult, which allows us to make this method async.
284
287
285
288
await this . sessionManager . start ( ) ;
286
289
@@ -426,6 +429,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
426
429
this . logger . writeVerbose ( `Dotnet attach debug configuration: ${ JSON . stringify ( dotnetAttachConfig , undefined , 2 ) } ` ) ;
427
430
this . logger . writeVerbose ( `Attached dotnet debugger to process: ${ pid } ` ) ;
428
431
}
432
+
429
433
return this . tempSessionDetails ;
430
434
}
431
435
@@ -452,7 +456,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
452
456
} ;
453
457
}
454
458
455
- /** Fetches all available vscode launch configurations. This is abstracted out for easier testing */
459
+ /** Fetches all available vscode launch configurations. This is abstracted out for easier testing. */
456
460
private getLaunchConfigurations ( ) : DebugConfiguration [ ] {
457
461
return workspace . getConfiguration ( "launch" ) . get < DebugConfiguration [ ] > ( "configurations" ) ?? [ ] ;
458
462
}
@@ -480,6 +484,17 @@ export class DebugSessionFeature extends LanguageClientConsumer
480
484
}
481
485
}
482
486
487
+ // NOTE: We don't support attaching to the Extension Terminal, even
488
+ // though in the past it looked like we did. The implementation was
489
+ // half-baked and left things unusable.
490
+ if ( config . processId === "current" || config . processId === await this . sessionManager . getLanguageServerPid ( ) ) {
491
+ // TODO: When (if ever) it's supported, we need to convert 0 and the
492
+ // old notion of "current" to the actual process ID, like this:
493
+ // config.processId = await this.sessionManager.getLanguageServerPid();
494
+ void this . logger . writeAndShowError ( "Attaching to the PowerShell Extension terminal is not supported. Please use the 'PowerShell: Interactive Session' debug configuration instead." ) ;
495
+ return PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG ;
496
+ }
497
+
483
498
if ( ! config . runspaceId && ! config . runspaceName ) {
484
499
config . runspaceId = await commands . executeCommand ( "PowerShell.PickRunspace" , config . processId ) ;
485
500
// No runspace selected. Cancel attach.
@@ -528,12 +543,13 @@ export class SpecifyScriptArgsFeature implements Disposable {
528
543
if ( text !== undefined ) {
529
544
await this . context . workspaceState . update ( powerShellDbgScriptArgsKey , text ) ;
530
545
}
546
+
531
547
return text ;
532
548
}
533
549
}
534
550
535
551
interface IProcessItem extends QuickPickItem {
536
- pid : string ; // payload for the QuickPick UI
552
+ processId : number ; // payload for the QuickPick UI
537
553
}
538
554
539
555
// eslint-disable-next-line @typescript-eslint/no-empty-interface
@@ -542,7 +558,7 @@ interface IGetPSHostProcessesArguments {
542
558
543
559
interface IPSHostProcessInfo {
544
560
processName : string ;
545
- processId : string ;
561
+ processId : number ;
546
562
appDomainName : string ;
547
563
mainWindowTitle : string ;
548
564
}
@@ -551,19 +567,16 @@ export const GetPSHostProcessesRequestType =
551
567
new RequestType < IGetPSHostProcessesArguments , IPSHostProcessInfo [ ] , string > ( "powerShell/getPSHostProcesses" ) ;
552
568
553
569
export class PickPSHostProcessFeature extends LanguageClientConsumer {
554
-
555
570
private command : Disposable ;
556
571
private waitingForClientToken ?: CancellationTokenSource ;
557
572
private getLanguageClientResolve ?: ( value : LanguageClient ) => void ;
558
573
559
574
constructor ( private logger : ILogger ) {
560
575
super ( ) ;
561
576
562
- this . command =
563
- commands . registerCommand ( "PowerShell.PickPSHostProcess" , ( ) => {
564
- return this . getLanguageClient ( )
565
- . then ( ( _ ) => this . pickPSHostProcess ( ) , ( _ ) => undefined ) ;
566
- } ) ;
577
+ this . command = commands . registerCommand ( "PowerShell.PickPSHostProcess" , async ( ) => {
578
+ return this . pickPSHostProcess ( ) ;
579
+ } ) ;
567
580
}
568
581
569
582
public override setLanguageClient ( languageClient : LanguageClient ) : void {
@@ -617,25 +630,24 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
617
630
}
618
631
}
619
632
620
- private async pickPSHostProcess ( ) : Promise < string | undefined > {
633
+ private async pickPSHostProcess ( ) : Promise < number | undefined > {
634
+ // We need the language client in order to send the request.
635
+ await this . getLanguageClient ( ) ;
636
+
621
637
// 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
- } ] ;
638
+ const items : IProcessItem [ ] = [ ] ;
627
639
628
640
const response = await this . languageClient ?. sendRequest ( GetPSHostProcessesRequestType , { } ) ;
629
641
for ( const process of response ?? [ ] ) {
630
642
let windowTitle = "" ;
631
643
if ( process . mainWindowTitle ) {
632
- windowTitle = `, Title: ${ process . mainWindowTitle } ` ;
644
+ windowTitle = `, ${ process . mainWindowTitle } ` ;
633
645
}
634
646
635
647
items . push ( {
636
648
label : process . processName ,
637
649
description : `PID: ${ process . processId . toString ( ) } ${ windowTitle } ` ,
638
- pid : process . processId ,
650
+ processId : process . processId ,
639
651
} ) ;
640
652
}
641
653
@@ -648,9 +660,10 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
648
660
matchOnDescription : true ,
649
661
matchOnDetail : true ,
650
662
} ;
663
+
651
664
const item = await window . showQuickPick ( items , options ) ;
652
665
653
- return item ? item . pid : undefined ;
666
+ return item ?. processId ?? undefined ;
654
667
}
655
668
656
669
private clearWaitingToken ( ) : void {
@@ -660,7 +673,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
660
673
}
661
674
662
675
interface IRunspaceItem extends QuickPickItem {
663
- id : string ; // payload for the QuickPick UI
676
+ id : number ; // payload for the QuickPick UI
664
677
}
665
678
666
679
// eslint-disable-next-line @typescript-eslint/no-empty-interface
@@ -677,18 +690,16 @@ export const GetRunspaceRequestType =
677
690
new RequestType < IGetRunspaceRequestArguments , IRunspace [ ] , string > ( "powerShell/getRunspace" ) ;
678
691
679
692
export class PickRunspaceFeature extends LanguageClientConsumer {
680
-
681
693
private command : Disposable ;
682
694
private waitingForClientToken ?: CancellationTokenSource ;
683
695
private getLanguageClientResolve ?: ( value : LanguageClient ) => void ;
684
696
685
697
constructor ( private logger : ILogger ) {
686
698
super ( ) ;
687
- this . command =
688
- commands . registerCommand ( "PowerShell.PickRunspace" , ( processId ) => {
689
- return this . getLanguageClient ( )
690
- . then ( ( _ ) => this . pickRunspace ( processId ) , ( _ ) => undefined ) ;
691
- } , this ) ;
699
+
700
+ this . command = commands . registerCommand ( "PowerShell.PickRunspace" ,
701
+ async ( processId ) => { return this . pickRunspace ( processId ) ; } ,
702
+ this ) ;
692
703
}
693
704
694
705
public override setLanguageClient ( languageClient : LanguageClient ) : void {
@@ -734,28 +745,26 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
734
745
this . clearWaitingToken ( ) ;
735
746
reject ( ) ;
736
747
737
- void this . logger . writeAndShowError ( "Attach to PowerShell host process: PowerShell session took too long to start." ) ;
748
+ void this . logger . writeAndShowError (
749
+ "Attach to PowerShell host process: PowerShell session took too long to start." ) ;
738
750
}
739
751
} , 60000 ) ;
740
752
} ,
741
753
) ;
742
754
}
743
755
}
744
756
745
- private async pickRunspace ( processId : string ) : Promise < string | undefined > {
757
+ private async pickRunspace ( processId : number ) : Promise < number | undefined > {
758
+ // We need the language client in order to send the request.
759
+ await this . getLanguageClient ( ) ;
760
+
746
761
const response = await this . languageClient ?. sendRequest ( GetRunspaceRequestType , { processId } ) ;
747
762
const items : IRunspaceItem [ ] = [ ] ;
748
763
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
764
items . push ( {
756
765
label : runspace . name ,
757
766
description : `ID: ${ runspace . id } - ${ runspace . availability } ` ,
758
- id : runspace . id . toString ( ) ,
767
+ id : runspace . id ,
759
768
} ) ;
760
769
}
761
770
@@ -764,9 +773,10 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
764
773
matchOnDescription : true ,
765
774
matchOnDetail : true ,
766
775
} ;
776
+
767
777
const item = await window . showQuickPick ( items , options ) ;
768
778
769
- return item ? item . id : undefined ;
779
+ return item ? .id ?? undefined ;
770
780
}
771
781
772
782
private clearWaitingToken ( ) : void {
0 commit comments