-
Notifications
You must be signed in to change notification settings - Fork 520
Add Debug Runspace command #1782
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
Changes from all commits
be326b5
e7d72b5
e72d1fe
35deb7a
64bb51c
0a31064
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,6 +80,20 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider | |
// if nothing is set, prompt for the processId | ||
if (!config.customPipeName && !config.processId) { | ||
config.processId = await vscode.commands.executeCommand("PowerShell.PickPSHostProcess"); | ||
|
||
// No process selected. Cancel attach. | ||
if (!config.processId) { | ||
return null; | ||
} | ||
} | ||
|
||
if (!config.runspaceId) { | ||
config.runspaceId = await vscode.commands.executeCommand("PowerShell.PickRunspace", config.processId); | ||
|
||
// No runspace selected. Cancel attach. | ||
if (!config.runspaceId) { | ||
return null; | ||
} | ||
} | ||
} | ||
|
||
|
@@ -386,3 +400,122 @@ export class PickPSHostProcessFeature implements IFeature { | |
} | ||
} | ||
} | ||
|
||
interface IRunspaceItem extends vscode.QuickPickItem { | ||
id: string; // payload for the QuickPick UI | ||
} | ||
|
||
interface IRunspace { | ||
id: number; | ||
name: string; | ||
availability: string; | ||
} | ||
|
||
export const GetRunspaceRequestType = | ||
new RequestType<any, IRunspace[], string, void>("powerShell/getRunspace"); | ||
|
||
export class PickRunspaceFeature implements IFeature { | ||
|
||
private command: vscode.Disposable; | ||
private languageClient: LanguageClient; | ||
private waitingForClientToken: vscode.CancellationTokenSource; | ||
private getLanguageClientResolve: (value?: LanguageClient | Thenable<LanguageClient>) => void; | ||
|
||
constructor() { | ||
this.command = | ||
vscode.commands.registerCommand("PowerShell.PickRunspace", (processId) => { | ||
return this.getLanguageClient() | ||
.then((_) => this.pickRunspace(processId), (_) => undefined); | ||
}, this); | ||
} | ||
|
||
public setLanguageClient(languageClient: LanguageClient) { | ||
this.languageClient = languageClient; | ||
|
||
if (this.waitingForClientToken) { | ||
this.getLanguageClientResolve(this.languageClient); | ||
this.clearWaitingToken(); | ||
} | ||
} | ||
|
||
public dispose() { | ||
this.command.dispose(); | ||
} | ||
|
||
private getLanguageClient(): Thenable<LanguageClient> { | ||
if (this.languageClient) { | ||
return Promise.resolve(this.languageClient); | ||
} else { | ||
// If PowerShell isn't finished loading yet, show a loading message | ||
// until the LanguageClient is passed on to us | ||
this.waitingForClientToken = new vscode.CancellationTokenSource(); | ||
|
||
return new Promise<LanguageClient>( | ||
(resolve, reject) => { | ||
this.getLanguageClientResolve = resolve; | ||
|
||
vscode.window | ||
.showQuickPick( | ||
["Cancel"], | ||
{ placeHolder: "Attach to PowerShell host process: Please wait, starting PowerShell..." }, | ||
this.waitingForClientToken.token) | ||
.then((response) => { | ||
if (response === "Cancel") { | ||
this.clearWaitingToken(); | ||
reject(); | ||
} | ||
}); | ||
|
||
// Cancel the loading prompt after 60 seconds | ||
setTimeout(() => { | ||
if (this.waitingForClientToken) { | ||
this.clearWaitingToken(); | ||
reject(); | ||
|
||
vscode.window.showErrorMessage( | ||
"Attach to PowerShell host process: PowerShell session took too long to start."); | ||
} | ||
}, 60000); | ||
}, | ||
); | ||
} | ||
} | ||
|
||
private pickRunspace(processId): Thenable<string> { | ||
return this.languageClient.sendRequest(GetRunspaceRequestType, processId).then((response) => { | ||
const items: IRunspaceItem[] = []; | ||
|
||
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 commentThe 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 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yep! Will get another PR in. |
||
continue; | ||
} | ||
|
||
items.push({ | ||
label: runspace.name, | ||
description: `ID: ${runspace.id} - ${runspace.availability}`, | ||
id: runspace.id.toString(), | ||
}); | ||
} | ||
|
||
const options: vscode.QuickPickOptions = { | ||
placeHolder: "Select PowerShell runspace to debug", | ||
matchOnDescription: true, | ||
matchOnDetail: true, | ||
}; | ||
|
||
return vscode.window.showQuickPick(items, options).then((item) => { | ||
// Return undefined when user presses Esc. | ||
// This prevents VSCode from opening launch.json in this case which happens if we return "". | ||
return item ? `${item.id}` : undefined; | ||
}); | ||
}); | ||
} | ||
|
||
private clearWaitingToken() { | ||
if (this.waitingForClientToken) { | ||
this.waitingForClientToken.dispose(); | ||
this.waitingForClientToken = undefined; | ||
} | ||
} | ||
} |