★ wanayoo — archive 1999 https://github.com/PowerShell/PowerShellEditorServices/pull/875Nouvelle recherche | Portail wanayoo
Skip to content
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

Add attach to local runspace. #875

Merged
merged 11 commits into from Mar 13, 2019

Conversation

@adamdriscoll
Copy link
Contributor

@adamdriscoll adamdriscoll commented Mar 7, 2019

Adds support for attaching to a local runspace. This extends the existing support for attaching to a runspace in a remote process. This enables debugging for modules that create additional runspaces such as ThreadJob, PoshRSJob and UnivesalDashboard.

@adamdriscoll
Copy link
Contributor Author

@adamdriscoll adamdriscoll commented Mar 7, 2019

Not seeing this test failure locally. I am seeing other failures that aren't listed in AppVeyor that seem unrelated to my PR.

@@ -21,5 +21,7 @@ public class AttachRequestArguments
public string ProcessId { get; set; }

public int RunspaceId { get; set; }

public string LocalRunspaceId { get; set; }

This comment has been minimized.

@rkeithhill

rkeithhill Mar 9, 2019
Collaborator

Just asking but ... do we really need two different fields for runspace id?

This comment has been minimized.

@rkeithhill

rkeithhill Mar 9, 2019
Collaborator

BTW if it would be more convenient if RunspaceId was a string, we change the type I think. We'd just update the VSCode debug attach code to stringify the runspace id number.

This comment has been minimized.

@adamdriscoll

adamdriscoll Mar 9, 2019
Author Contributor

OK. I can make that change. That's pretty much the reason I added another field was that I didn't wanna mess with RunspaceId's type but I'm happy to adjust that to eliminate the new property.

This comment has been minimized.

@adamdriscoll

adamdriscoll Mar 9, 2019
Author Contributor

I guess I was curious how this affects existing launch.json files. Is there something we need to do to ensure that they get upgraded in some way or will a number just work?

This comment has been minimized.

@adamdriscoll

adamdriscoll Mar 9, 2019
Author Contributor

I just tried this. Seems to still work. It complains in the launch.json that the number should be a string but the attaching still works.

{
runspaceId = attachParams.RunspaceId > 0 ? attachParams.RunspaceId : 1;
}
else if (int.TryParse(attachParams.LocalRunspaceId, out int localRunspaceId))

This comment has been minimized.

@rkeithhill

rkeithhill Mar 9, 2019
Collaborator

Seems like we could int.TryParse() on a string typed RunspaceId. In the normal "attach" case we'd just set it to "1". Your new debug config would set it to whatever the user picks from the runspace id pick list.

This comment has been minimized.

@adamdriscoll

adamdriscoll Mar 9, 2019
Author Contributor

Sweet. Works for me. I will update these PRs sometime this weekend.

@@ -417,16 +417,18 @@ protected void Stop()
return;
}

await _editorSession.PowerShellContext.ExecuteScriptStringAsync(
if (attachParams.ProcessId != "current") {

This comment has been minimized.

@TylerLeonhardt

TylerLeonhardt Mar 11, 2019
Member

Shouldn't need this if because the outer if tries to parse the ProcessId as an integer (L411):

if (processIdIsSet && int.TryParse(attachParams.ProcessId, out int processId) && (processId > 0))

This comment has been minimized.

@adamdriscoll

adamdriscoll Mar 11, 2019
Author Contributor

Good catch. Updated the PR.

int runspaceId = 1;
if (int.TryParse(attachParams.RunspaceId, out runspaceId))
{
runspaceId = runspaceId > 0 ? runspaceId : 1;

This comment has been minimized.

@TylerLeonhardt

TylerLeonhardt Mar 11, 2019
Member

I would maybe factor this into the if

if (!int.TryParse(attachParams.RunspaceId, out 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.");

    return;
}

This comment has been minimized.

@adamdriscoll

adamdriscoll Mar 11, 2019
Author Contributor

👍

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Looking good! Just some general comments and questions.

var psCommand = new PSCommand();
psCommand.AddCommand("Get-Runspace");

var runspaces = await editorSession.PowerShellContext.ExecuteCommandAsync<PSObject>(psCommand);

This comment has been minimized.

@TylerLeonhardt

TylerLeonhardt Mar 11, 2019
Member

can you replace var with the type since this is a tad more complicated than new Blah()

This comment has been minimized.

@TylerLeonhardt

TylerLeonhardt Mar 11, 2019
Member

Also, instead of PSObject you should be able to do System.Management.Automation.Runspaces.Runspace and then you don't have to use dynamic below.

This comment has been minimized.

@adamdriscoll

adamdriscoll Mar 11, 2019
Author Contributor

👍

{
var runspaceResponses = new List<GetRunspaceResponse>();

if (this.editorSession.PowerShellContext.LocalPowerShellVersion.Version.Major >= 5)

This comment has been minimized.

@TylerLeonhardt

TylerLeonhardt Mar 11, 2019
Member

Was Get-Runspace added in 5?

This comment has been minimized.

@adamdriscoll

adamdriscoll Mar 11, 2019
Author Contributor

That's a really good question. I just took that check from the process picker but I'm not sure when Debug-Runspace\Get-Runspace was added. I can try and find out.

This comment has been minimized.

@adamdriscoll

adamdriscoll Mar 11, 2019
Author Contributor

image

This comment has been minimized.

@TylerLeonhardt

TylerLeonhardt Mar 11, 2019
Member

Well looks like that answers our question :)

TylerLeonhardt and others added 3 commits Mar 11, 2019
It's neat that we can just commit a suggestion.

Co-Authored-By: adamdriscoll <adamdriscoll@users.noreply.github.com>
Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

LGTM! I'm excited for this code path to see more usage. It's a very nice feature of the extension.

@TylerLeonhardt
Copy link
Member

@TylerLeonhardt TylerLeonhardt commented Mar 12, 2019 •

@adamdriscoll if you couldn't tell already, that test is flaky... I've been meaning to fix it, but I haven't had the time. I will address it as soon as I can.

restarted build.

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

just a couple nits really. Basically looks good.

@@ -1222,17 +1222,27 @@ public static string GetDecoratedSymbolName(SymbolReference symbolReference)
}

protected async Task HandleGetRunspaceRequestAsync(
object noParams,
object processId,

This comment has been minimized.

@TylerLeonhardt

TylerLeonhardt Mar 12, 2019
Member

Does this have to be object? Or can we turn it into a string?

This comment has been minimized.

@adamdriscoll

adamdriscoll Mar 13, 2019
Author Contributor

You're right. Changed to a string.

@@ -1246,6 +1256,12 @@ public static string GetDecoratedSymbolName(SymbolReference symbolReference)
});
}
}

if (processId != null && processId.ToString() != "current") {

This comment has been minimized.

@TylerLeonhardt

TylerLeonhardt Mar 12, 2019
Member

Since you do this comparison a couple times, maybe do a:

bool isCurrentProcess = processId != null && processId.ToString() != "current";

and use that.

This comment has been minimized.

@adamdriscoll

adamdriscoll Mar 13, 2019
Author Contributor

Works for me. Done.

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

LGTM! Excited to get this in!

@TylerLeonhardt TylerLeonhardt merged commit 13d8f8a into PowerShell:master Mar 13, 2019
3 checks passed
3 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
license/cla All CLA requirements met.
Details
TylerLeonhardt added a commit to TylerLeonhardt/PowerShellEditorServices that referenced this pull request Mar 18, 2019
* Add attach to local runspace.

* Remove comment.

* Use single runspaceId property.

* Remove unnecessary processId check.

* Factored if.

* Update src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

It's neat that we can just commit a suggestion.

Co-Authored-By: adamdriscoll <adamdriscoll@users.noreply.github.com>

* Use runspace rather than dynamic.

* Accept process ID for GetRunspaceRequest.

* Clean up.
TylerLeonhardt added a commit that referenced this pull request Mar 20, 2019
* Add attach to local runspace.

* Remove comment.

* Use single runspaceId property.

* Remove unnecessary processId check.

* Factored if.

* Update src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs

It's neat that we can just commit a suggestion.

Co-Authored-By: adamdriscoll <adamdriscoll@users.noreply.github.com>

* Use runspace rather than dynamic.

* Accept process ID for GetRunspaceRequest.

* Clean up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.