@@ -469,22 +469,35 @@ await requestContext.SendErrorAsync(
469
469
// InitializedEvent will be sent as soon as the RunspaceChanged
470
470
// event gets fired with the attached runspace.
471
471
472
- var runspaceId = 1 ;
473
- if ( ! int . TryParse ( attachParams . RunspaceId , out runspaceId ) || runspaceId <= 0 )
472
+ string debugRunspaceCmd ;
473
+ if ( attachParams . RunspaceName != null )
474
474
{
475
- Logger . Write (
476
- LogLevel . Error ,
477
- $ "Attach request failed, '{ attachParams . RunspaceId } ' is an invalid value for the processId.") ;
475
+ debugRunspaceCmd = $ "\n Debug-Runspace -Name '{ attachParams . RunspaceName } '";
476
+ }
477
+ else if ( attachParams . RunspaceId != null )
478
+ {
479
+ if ( ! int . TryParse ( attachParams . RunspaceId , out int runspaceId ) || runspaceId <= 0 )
480
+ {
481
+ Logger . Write (
482
+ LogLevel . Error ,
483
+ $ "Attach request failed, '{ attachParams . RunspaceId } ' is an invalid value for the processId.") ;
478
484
479
- await requestContext . SendErrorAsync (
480
- "A positive integer must be specified for the RunspaceId field." ) ;
485
+ await requestContext . SendErrorAsync (
486
+ "A positive integer must be specified for the RunspaceId field." ) ;
481
487
482
- return ;
488
+ return ;
489
+ }
490
+
491
+ debugRunspaceCmd = $ "\n Debug-Runspace -Id { runspaceId } ";
492
+ }
493
+ else
494
+ {
495
+ debugRunspaceCmd = "\n Debug-Runspace -Id 1" ;
483
496
}
484
497
485
498
_waitingForAttach = true ;
486
499
Task nonAwaitedTask = _editorSession . PowerShellContext
487
- . ExecuteScriptStringAsync ( $ " \n Debug-Runspace -Id { runspaceId } " )
500
+ . ExecuteScriptStringAsync ( debugRunspaceCmd )
488
501
. ContinueWith ( OnExecutionCompletedAsync ) ;
489
502
490
503
await requestContext . SendResultAsync ( null ) ;
0 commit comments