diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs index 185a1aac0..4c805a2b1 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs @@ -22,6 +22,8 @@ public class AttachRequestArguments public string RunspaceId { get; set; } + public string RunspaceName { get; set; } + public string CustomPipeName { get; set; } } } diff --git a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs index c3e203829..3faa9bbca 100644 --- a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs +++ b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs @@ -464,22 +464,35 @@ await requestContext.SendError( // InitializedEvent will be sent as soon as the RunspaceChanged // event gets fired with the attached runspace. - var runspaceId = 1; - if (!int.TryParse(attachParams.RunspaceId, out runspaceId) || runspaceId <= 0) + string debugRunspaceCmd; + if (attachParams.RunspaceName != null) { - Logger.Write( - LogLevel.Error, - $"Attach request failed, '{attachParams.RunspaceId}' is an invalid value for the processId."); + debugRunspaceCmd = $"\nDebug-Runspace -Name '{attachParams.RunspaceName}'"; + } + else if (attachParams.RunspaceId != null) + { + if (!int.TryParse(attachParams.RunspaceId, out int runspaceId) || runspaceId <= 0) + { + Logger.Write( + LogLevel.Error, + $"Attach request failed, '{attachParams.RunspaceId}' is an invalid value for the processId."); - await requestContext.SendError( - "A positive integer must be specified for the RunspaceId field."); + await requestContext.SendError( + "A positive integer must be specified for the RunspaceId field."); - return; + return; + } + + debugRunspaceCmd = $"\nDebug-Runspace -Id {runspaceId}"; + } + else + { + debugRunspaceCmd = "\nDebug-Runspace -Id 1"; } _waitingForAttach = true; Task nonAwaitedTask = _editorSession.PowerShellContext - .ExecuteScriptString($"\nDebug-Runspace -Id {runspaceId}") + .ExecuteScriptString(debugRunspaceCmd) .ContinueWith(OnExecutionCompleted); await requestContext.SendResult(null);