From 7ac96d54124ace669e5237cfc94b6f1b8aa1221b Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Mon, 6 May 2019 16:35:04 -0700 Subject: [PATCH 1/3] Allow passing runspace name --- .../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..a3b26fac6 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 object 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 5db738b80..1c6fa6dff 100644 --- a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs +++ b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs @@ -470,22 +470,35 @@ await requestContext.SendErrorAsync( // 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.SendErrorAsync( - "A positive integer must be specified for the RunspaceId field."); + await requestContext.SendErrorAsync( + "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 - .ExecuteScriptStringAsync($"\nDebug-Runspace -Id {runspaceId}") + .ExecuteScriptStringAsync(debugRunspaceCmd) .ContinueWith(OnExecutionCompletedAsync); await requestContext.SendResultAsync(null); From 1af0080254148823531072792f2e9705e630de4b Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Tue, 7 May 2019 14:18:02 -0700 Subject: [PATCH 2/3] change object to string --- .../DebugAdapter/AttachRequest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs index a3b26fac6..4c805a2b1 100644 --- a/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs +++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs @@ -22,7 +22,7 @@ public class AttachRequestArguments public string RunspaceId { get; set; } - public object RunspaceName { get; set; } + public string RunspaceName { get; set; } public string CustomPipeName { get; set; } } From 3b83ef9bb810ce323f8ab7c687bc9e34bab413c2 Mon Sep 17 00:00:00 2001 From: Tyler James Leonhardt Date: Tue, 21 May 2019 14:00:07 -0700 Subject: [PATCH 3/3] Apply suggestions from code review spaces Co-Authored-By: Robert Holt --- src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs index 1c6fa6dff..db7aed82d 100644 --- a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs +++ b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs @@ -471,11 +471,11 @@ await requestContext.SendErrorAsync( // event gets fired with the attached runspace. string debugRunspaceCmd; - if(attachParams.RunspaceName != null) + if (attachParams.RunspaceName != null) { debugRunspaceCmd = $"\nDebug-Runspace -Name '{attachParams.RunspaceName}'"; } - else if(attachParams.RunspaceId != null) + else if (attachParams.RunspaceId != null) { if (!int.TryParse(attachParams.RunspaceId, out int runspaceId) || runspaceId <= 0) {