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 Debug Runspace command #1782

Merged
merged 6 commits into from
Mar 13, 2019

Conversation

adamdriscoll
Copy link
Contributor

PR Summary

This enables support for attaching to local runspaces. This adds a new command that allows the user to select a local runspace and attach to it. This is similar to attaching to a remote process and uses the same PSES request.

The accompanying PR in PSES is here: PowerShell/PowerShellEditorServices#875

PR Checklist

Note: Tick the boxes below that apply to this pull request by putting an x between the square brackets.
Please mark anything not applicable to this PR NA.

  • [ x] PR has a meaningful title
  • [ x] Summarized changes
  • [ -] PR has tests
  • [x ] This PR is ready to merge and is not work in progress
    • If the PR is work in progress, please add the prefix WIP: to the beginning of the title and remove the prefix when the PR is ready

package.json Outdated
@@ -36,7 +36,8 @@
"onCommand:PowerShell.ShowSessionConsole",
"onCommand:PowerShell.ShowSessionMenu",
"onCommand:PowerShell.RestartSession",
"onView:PowerShellCommands"
"onView:PowerShellCommands",
"onCommand:PowerShell.PickRunspace"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit, could you sort this up by the other "Pick" command?

package.json Outdated
@@ -407,6 +409,17 @@
"request": "launch",
"cwd": ""
}
},
{
"label": "PowerShell: Debug Runspace",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we mention this applies to the "current" PSIC session. In other places, we refer to this as the "Interactive Session". Also, since this is an "attach" it probably should be named something like PowerShell Attach Interactive Session Runspace. Or maybe I'm misunderstanding the "current" process id value?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current was just a way to signal to PSES that we wanna attach to the current process and not some other remote process. I kinda wanted to avoid this all together and just set the process ID to the current PSES process ID but couldn't find a nice clean way to do that. We can call this whatever makes sense. If interactive session makes more sense, let's do it.

package.json Outdated
@@ -495,6 +513,13 @@
"type": "powershell",
"request": "launch",
"cwd": ""
},
{
"name": "PowerShell Debug Runspace",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be same as what decide to use for a name on line 414.

@TylerLeonhardt
Copy link
Member

Hey @adamdriscoll! This is awesome. I'd love to help UD customers and the likes.

Just so you know, I just merged in #1775 and PowerShell/PowerShellEditorServices#871 which changes the way the attach launch config works.

You might have to do some slight refactoring to address that - apologies for making you do that!

FWIW, I've moved the logic for prompting for the process id to here.

I think this will allow you to set processId to current and work just fine with the logic you've got in PSES.

Let me know if you need anything.

@adamdriscoll
Copy link
Contributor Author

@TylerLeonhardt It's all good. I'll take a look at the changes and get this PR refactored.

@adamdriscoll
Copy link
Contributor Author

@TylerLeonhardt Merged your changes. Had to only make slight changes to this PR and the PSES PR.

package.json Outdated
@@ -447,9 +460,9 @@
"default": null
},
"runspaceId": {
"type": "number",
"type": "string",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really wish it were possible to do like string | int for this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually... it looks like you can do:

"type":["string","number"]

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamdriscoll I think you maybe missed this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. In there now.

package.json Outdated
@@ -491,13 +504,20 @@
"name": "PowerShell Attach to Host Process",
"type": "PowerShell",
"request": "attach",
"runspaceId": 1
"runspaceId": "1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should go ahead and make this ${command:PickRunspace} now?

thoughts @rkeithhill @rjmholt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So would the workflow be 1) query PSES for host processes 2) user picks host process, 3) query PSES for runspaces in the selected host process and 4) user picks runspace? If so, that sounds pretty good to me. Although I have a feeling the vast majority of time the user will pick runspace 1. If they get tired of the prompt, I guess then could then hard-code 1 into the debug config.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly! Ok. Lets do that. @adamdriscoll can you follow #1775 and implement it in a similar fashion?

Ideally, the user should not have to put anything for runspaceId and it will prompt them for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After starting to implement this I realized I needed to update the request to pass in a process ID for the request runspace command. I kinda got that working but am seeing weird stuff where its complaining about null values and stating the "Attach to Host Process" debugger is already running when I cancel out of the pickers.

I will revisit tomorrow but it's not as simple as I thought at first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if there's anything you need from us :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got this working. Updated this PR and the PSES PR to support process ID and to pop up the picker in the same place as the process picker.

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

private getLanguageClientResolve: (value?: LanguageClient | Thenable<LanguageClient>) => void;

constructor() {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can probably get rid of this newline

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return this.languageClient.sendRequest(GetRunspaceRequestType, null).then((runspaces) => {
const items: IRunspaceItem[] = [];

for (const p in runspaces) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can probably switch this to a for...of loop then you don't have to index, you can just do:

for (const runspace of runspaces)

and runspace is an IRunspaceItem

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Latest commit fixes this. There was actually a mismatch in the PSES response type and the VS Code response type.

package.json Outdated
"description": "Optional: The ID of the runspace to debug in the attached process. Defaults to 1. Works only on PowerShell 5 and above.",
"default": 1
"default": "1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the things I did in #1775 was made the default for processId to be null and then prompt for it when resolving the debug config:

if (!config.customPipeName && !config.processId) {
config.processId = await vscode.commands.executeCommand("PowerShell.PickPSHostProcess");
}

@rkeithhill @rjmholt if we want to make prompting for PickRunspace to be the default, it should probably be implemented in a similar fashion.

package.json Outdated
"type": "PowerShell",
"request": "attach",
"processId": "current",
"runspaceId": "^\"\\${command:PickRunspace}\""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@TylerLeonhardt TylerLeonhardt merged commit b1c5f5f into PowerShell:master Mar 13, 2019

for (const runspace of response) {
// Skip default runspace
if (runspace.id === 1 || runspace.name === "PSAttachRunspace") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally just realized that this should only be filtered out IF in the current process...

If we're in a different process, we probably want to attach to runspace 1.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adamdriscoll can you fix this up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep! Will get another PR in.

TylerLeonhardt pushed a commit to TylerLeonhardt/vscode-powershell that referenced this pull request Mar 18, 2019
* Add Debug Runspace command

* Update package.json based on feedback.

* Update response to match PSES response.

* Change how we ask for RunspaceId.

* Clean up.
TylerLeonhardt pushed a commit that referenced this pull request Mar 20, 2019
* Add Debug Runspace command

* Update package.json based on feedback.

* Update response to match PSES response.

* Change how we ask for RunspaceId.

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

Successfully merging this pull request may close these issues.

3 participants