Skip to content

Allow passing RunspaceName (#951) #957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class AttachRequestArguments

public string RunspaceId { get; set; }

public string RunspaceName { get; set; }

public string CustomPipeName { get; set; }
}
}
31 changes: 22 additions & 9 deletions src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down