From c11e78ebf87d8416e7e384cbc392d09e5459717b Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Tue, 21 May 2019 14:31:32 -0700 Subject: [PATCH] Allow passing RunspaceName (#951) * Allow passing runspace name * change object to string * Apply suggestions from code review spaces Co-Authored-By: Robert Holt --- .../DebugAdapter/AttachRequest.cs | 2 ++ .../Server/DebugAdapter.cs | 31 +++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) 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);