@@ -469,22 +469,35 @@ await requestContext.SendErrorAsync(
469469 // InitializedEvent will be sent as soon as the RunspaceChanged
470470 // event gets fired with the attached runspace.
471471
472- var runspaceId = 1 ;
473- if ( ! int . TryParse ( attachParams . RunspaceId , out runspaceId ) || runspaceId <= 0 )
472+ string debugRunspaceCmd ;
473+ if ( attachParams . RunspaceName != null )
474474 {
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.") ;
478484
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." ) ;
481487
482- return ;
488+ return ;
489+ }
490+
491+ debugRunspaceCmd = $ "\n Debug-Runspace -Id { runspaceId } ";
492+ }
493+ else
494+ {
495+ debugRunspaceCmd = "\n Debug-Runspace -Id 1" ;
483496 }
484497
485498 _waitingForAttach = true ;
486499 Task nonAwaitedTask = _editorSession . PowerShellContext
487- . ExecuteScriptStringAsync ( $ " \n Debug-Runspace -Id { runspaceId } " )
500+ . ExecuteScriptStringAsync ( debugRunspaceCmd )
488501 . ContinueWith ( OnExecutionCompletedAsync ) ;
489502
490503 await requestContext . SendResultAsync ( null ) ;
0 commit comments