@@ -464,22 +464,35 @@ await requestContext.SendError(
464464 // InitializedEvent will be sent as soon as the RunspaceChanged
465465 // event gets fired with the attached runspace.
466466
467- var runspaceId = 1 ;
468- if ( ! int . TryParse ( attachParams . RunspaceId , out runspaceId ) || runspaceId <= 0 )
467+ string debugRunspaceCmd ;
468+ if ( attachParams . RunspaceName != null )
469469 {
470- Logger . Write (
471- LogLevel . Error ,
472- $ "Attach request failed, '{ attachParams . RunspaceId } ' is an invalid value for the processId.") ;
470+ debugRunspaceCmd = $ "\n Debug-Runspace -Name '{ attachParams . RunspaceName } '";
471+ }
472+ else if ( attachParams . RunspaceId != null )
473+ {
474+ if ( ! int . TryParse ( attachParams . RunspaceId , out int runspaceId ) || runspaceId <= 0 )
475+ {
476+ Logger . Write (
477+ LogLevel . Error ,
478+ $ "Attach request failed, '{ attachParams . RunspaceId } ' is an invalid value for the processId.") ;
473479
474- await requestContext . SendError (
475- "A positive integer must be specified for the RunspaceId field." ) ;
480+ await requestContext . SendError (
481+ "A positive integer must be specified for the RunspaceId field." ) ;
476482
477- return ;
483+ return ;
484+ }
485+
486+ debugRunspaceCmd = $ "\n Debug-Runspace -Id { runspaceId } ";
487+ }
488+ else
489+ {
490+ debugRunspaceCmd = "\n Debug-Runspace -Id 1" ;
478491 }
479492
480493 _waitingForAttach = true ;
481494 Task nonAwaitedTask = _editorSession . PowerShellContext
482- . ExecuteScriptString ( $ " \n Debug-Runspace -Id { runspaceId } " )
495+ . ExecuteScriptString ( debugRunspaceCmd )
483496 . ContinueWith ( OnExecutionCompleted ) ;
484497
485498 await requestContext . SendResult ( null ) ;
0 commit comments