Skip to content

Commit

Permalink
Allow passing RunspaceName (#951)
Browse files Browse the repository at this point in the history
* Allow passing runspace name

* change object to string

* Apply suggestions from code review

spaces

Co-Authored-By: Robert Holt <rjmholt@gmail.com>
  • Loading branch information
TylerLeonhardt and rjmholt authored May 21, 2019
1 parent 14ddd0f commit 55d01fc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
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 @@ -469,22 +469,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);
Expand Down

0 comments on commit 55d01fc

Please sign in to comment.