-
Notifications
You must be signed in to change notification settings - Fork 502
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
Add Debug Runspace command #1782
Conversation
package.json
Outdated
@@ -36,7 +36,8 @@ | |||
"onCommand:PowerShell.ShowSessionConsole", | |||
"onCommand:PowerShell.ShowSessionMenu", | |||
"onCommand:PowerShell.RestartSession", | |||
"onView:PowerShellCommands" | |||
"onView:PowerShellCommands", | |||
"onCommand:PowerShell.PickRunspace" |
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
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.
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 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 Let me know if you need anything. |
@TylerLeonhardt It's all good. I'll take a look at the changes and get this PR refactored. |
@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", |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"]
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 :)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
src/features/DebugSession.ts
Outdated
private getLanguageClientResolve: (value?: LanguageClient | Thenable<LanguageClient>) => void; | ||
|
||
constructor() { | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/features/DebugSession.ts
Outdated
return this.languageClient.sendRequest(GetRunspaceRequestType, null).then((runspaces) => { | ||
const items: IRunspaceItem[] = []; | ||
|
||
for (const p in runspaces) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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:
vscode-powershell/src/features/DebugSession.ts
Lines 81 to 83 in 1db2283
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}\"" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
|
||
for (const runspace of response) { | ||
// Skip default runspace | ||
if (runspace.id === 1 || runspace.name === "PSAttachRunspace") { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
* Add Debug Runspace command * Update package.json based on feedback. * Update response to match PSES response. * Change how we ask for RunspaceId. * Clean up.
* Add Debug Runspace command * Update package.json based on feedback. * Update response to match PSES response. * Change how we ask for RunspaceId. * Clean up.
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
.WIP:
to the beginning of the title and remove the prefix when the PR is ready