@@ -426,6 +426,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
426426 this . logger . writeVerbose ( `Dotnet attach debug configuration: ${ JSON . stringify ( dotnetAttachConfig , undefined , 2 ) } ` ) ;
427427 this . logger . writeVerbose ( `Attached dotnet debugger to process: ${ pid } ` ) ;
428428 }
429+
429430 return this . tempSessionDetails ;
430431 }
431432
@@ -452,7 +453,7 @@ export class DebugSessionFeature extends LanguageClientConsumer
452453 } ;
453454 }
454455
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. */
456457 private getLaunchConfigurations ( ) : DebugConfiguration [ ] {
457458 return workspace . getConfiguration ( "launch" ) . get < DebugConfiguration [ ] > ( "configurations" ) ?? [ ] ;
458459 }
@@ -471,6 +472,10 @@ export class DebugSessionFeature extends LanguageClientConsumer
471472 return PREVENT_DEBUG_START ;
472473 }
473474
475+ if ( config . processId === 0 || config . processId === "current" ) {
476+ config . processId = await this . sessionManager . getLanguageServerPid ( ) ;
477+ }
478+
474479 // If nothing is set, prompt for the processId.
475480 if ( ! config . customPipeName && ! config . processId ) {
476481 config . processId = await commands . executeCommand ( "PowerShell.PickPSHostProcess" ) ;
@@ -528,12 +533,13 @@ export class SpecifyScriptArgsFeature implements Disposable {
528533 if ( text !== undefined ) {
529534 await this . context . workspaceState . update ( powerShellDbgScriptArgsKey , text ) ;
530535 }
536+
531537 return text ;
532538 }
533539}
534540
535541interface IProcessItem extends QuickPickItem {
536- pid : string ; // payload for the QuickPick UI
542+ processId : number ; // payload for the QuickPick UI
537543}
538544
539545// eslint-disable-next-line @typescript-eslint/no-empty-interface
@@ -542,7 +548,7 @@ interface IGetPSHostProcessesArguments {
542548
543549interface IPSHostProcessInfo {
544550 processName : string ;
545- processId : string ;
551+ processId : number ;
546552 appDomainName : string ;
547553 mainWindowTitle : string ;
548554}
@@ -551,19 +557,16 @@ export const GetPSHostProcessesRequestType =
551557 new RequestType < IGetPSHostProcessesArguments , IPSHostProcessInfo [ ] , string > ( "powerShell/getPSHostProcesses" ) ;
552558
553559export class PickPSHostProcessFeature extends LanguageClientConsumer {
554-
555560 private command : Disposable ;
556561 private waitingForClientToken ?: CancellationTokenSource ;
557562 private getLanguageClientResolve ?: ( value : LanguageClient ) => void ;
558563
559564 constructor ( private logger : ILogger ) {
560565 super ( ) ;
561566
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+ } ) ;
567570 }
568571
569572 public override setLanguageClient ( languageClient : LanguageClient ) : void {
@@ -617,25 +620,24 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
617620 }
618621 }
619622
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+
621627 // 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 [ ] = [ ] ;
627629
628630 const response = await this . languageClient ?. sendRequest ( GetPSHostProcessesRequestType , { } ) ;
629631 for ( const process of response ?? [ ] ) {
630632 let windowTitle = "" ;
631633 if ( process . mainWindowTitle ) {
632- windowTitle = `, Title: ${ process . mainWindowTitle } ` ;
634+ windowTitle = `, ${ process . mainWindowTitle } ` ;
633635 }
634636
635637 items . push ( {
636638 label : process . processName ,
637639 description : `PID: ${ process . processId . toString ( ) } ${ windowTitle } ` ,
638- pid : process . processId ,
640+ processId : process . processId ,
639641 } ) ;
640642 }
641643
@@ -648,9 +650,10 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
648650 matchOnDescription : true ,
649651 matchOnDetail : true ,
650652 } ;
653+
651654 const item = await window . showQuickPick ( items , options ) ;
652655
653- return item ? item . pid : undefined ;
656+ return item ?. processId ?? undefined ;
654657 }
655658
656659 private clearWaitingToken ( ) : void {
@@ -660,7 +663,7 @@ export class PickPSHostProcessFeature extends LanguageClientConsumer {
660663}
661664
662665interface IRunspaceItem extends QuickPickItem {
663- id : string ; // payload for the QuickPick UI
666+ id : number ; // payload for the QuickPick UI
664667}
665668
666669// eslint-disable-next-line @typescript-eslint/no-empty-interface
@@ -677,18 +680,16 @@ export const GetRunspaceRequestType =
677680 new RequestType < IGetRunspaceRequestArguments , IRunspace [ ] , string > ( "powerShell/getRunspace" ) ;
678681
679682export class PickRunspaceFeature extends LanguageClientConsumer {
680-
681683 private command : Disposable ;
682684 private waitingForClientToken ?: CancellationTokenSource ;
683685 private getLanguageClientResolve ?: ( value : LanguageClient ) => void ;
684686
685687 constructor ( private logger : ILogger ) {
686688 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 ) ;
692693 }
693694
694695 public override setLanguageClient ( languageClient : LanguageClient ) : void {
@@ -734,28 +735,26 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
734735 this . clearWaitingToken ( ) ;
735736 reject ( ) ;
736737
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." ) ;
738740 }
739741 } , 60000 ) ;
740742 } ,
741743 ) ;
742744 }
743745 }
744746
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+
746751 const response = await this . languageClient ?. sendRequest ( GetRunspaceRequestType , { processId } ) ;
747752 const items : IRunspaceItem [ ] = [ ] ;
748753 for ( const runspace of response ?? [ ] ) {
749- // Skip default runspace
750- if ( ( runspace . id === 1 || runspace . name === "PSAttachRunspace" )
751- && processId === "current" ) {
752- continue ;
753- }
754-
755754 items . push ( {
756755 label : runspace . name ,
757756 description : `ID: ${ runspace . id } - ${ runspace . availability } ` ,
758- id : runspace . id . toString ( ) ,
757+ id : runspace . id ,
759758 } ) ;
760759 }
761760
@@ -764,9 +763,10 @@ export class PickRunspaceFeature extends LanguageClientConsumer {
764763 matchOnDescription : true ,
765764 matchOnDetail : true ,
766765 } ;
766+
767767 const item = await window . showQuickPick ( items , options ) ;
768768
769- return item ? item . id : undefined ;
769+ return item ? .id ?? undefined ;
770770 }
771771
772772 private clearWaitingToken ( ) : void {
0 commit comments