Skip to content

Commit 55d01fc

Browse files
Allow passing RunspaceName (#951)
* Allow passing runspace name * change object to string * Apply suggestions from code review spaces Co-Authored-By: Robert Holt <[email protected]>
1 parent 14ddd0f commit 55d01fc

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class AttachRequestArguments
2222

2323
public string RunspaceId { get; set; }
2424

25+
public string RunspaceName { get; set; }
26+
2527
public string CustomPipeName { get; set; }
2628
}
2729
}

src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = $"\nDebug-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 = $"\nDebug-Runspace -Id {runspaceId}";
492+
}
493+
else
494+
{
495+
debugRunspaceCmd = "\nDebug-Runspace -Id 1";
483496
}
484497

485498
_waitingForAttach = true;
486499
Task nonAwaitedTask = _editorSession.PowerShellContext
487-
.ExecuteScriptStringAsync($"\nDebug-Runspace -Id {runspaceId}")
500+
.ExecuteScriptStringAsync(debugRunspaceCmd)
488501
.ContinueWith(OnExecutionCompletedAsync);
489502

490503
await requestContext.SendResultAsync(null);

0 commit comments

Comments
 (0)