Skip to content

Commit bbcbcb5

Browse files
Allow passing RunspaceName (#951) (#957)
* Allow passing runspace name * change object to string * Apply suggestions from code review spaces Co-Authored-By: Robert Holt <rjmholt@gmail.com>
1 parent e515a07 commit bbcbcb5

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

src/PowerShellEditorServices.Protocol/DebugAdapter/AttachRequest.cs

+2
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

+22-9
Original file line numberDiff line numberDiff line change
@@ -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 = $"\nDebug-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 = $"\nDebug-Runspace -Id {runspaceId}";
487+
}
488+
else
489+
{
490+
debugRunspaceCmd = "\nDebug-Runspace -Id 1";
478491
}
479492

480493
_waitingForAttach = true;
481494
Task nonAwaitedTask = _editorSession.PowerShellContext
482-
.ExecuteScriptString($"\nDebug-Runspace -Id {runspaceId}")
495+
.ExecuteScriptString(debugRunspaceCmd)
483496
.ContinueWith(OnExecutionCompleted);
484497

485498
await requestContext.SendResult(null);

0 commit comments

Comments
 (0)