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

Fix host process picker when session init'd. #437

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,12 @@
}
},
{
"label": "PowerShell: Attach to PowerShell Process Configuration",
"description": "A new configuration for debugging a runspace in another process.",
"label": "PowerShell: Attach to PowerShell Host Process Configuration",
"description": "A new configuration for debugging a runspace in another host process.",
"body": {
"type": "PowerShell",
"request": "attach",
"name": "PowerShell Attach to Process",
"name": "PowerShell Attach to Host Process",
"processId": "^\"\\${command.PickPSHostProcess}\"",
"runspaceId": 1
}
Expand Down Expand Up @@ -251,7 +251,7 @@
},
"processId": {
"type": "string",
"description": "Id of PowerShell host process to attach to. Works only on PowerShell 5 and above.",
"description": "The process id of the PowerShell host process to attach to. Works only on PowerShell 5 and above.",
"default": "${command.PickPSHostProcess}"
},
"runspaceId": {
Expand All @@ -274,8 +274,9 @@
{
"type": "PowerShell",
"request": "attach",
"name": "PowerShell Attach",
"processId": "12345"
"name": "PowerShell Attach to Host Process",
"processId": "${command.PickPSHostProcess}",
"runspaceId": 1
},
{
"type": "PowerShell",
Expand Down
72 changes: 40 additions & 32 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,32 @@ export class PickPSHostProcessFeature implements IFeature {

// If PowerShell isn't finished loading yet, show a loading message
// until the LanguageClient is passed on to us
var cancelled = false;
var timedOut = false;
this.waitingForClientToken = new vscode.CancellationTokenSource();

vscode.window
.showQuickPick(
["Cancel"],
{ placeHolder: "Select PowerShell Host Process to attach to: Please wait, starting PowerShell..." },
{ placeHolder: "Attach to PowerShell host process: Please wait, starting PowerShell..." },
this.waitingForClientToken.token)
.then(response => { if (response === "Cancel") { this.clearWaitingToken(); } });
.then(response => {
if (response === "Cancel") {
this.clearWaitingToken();
}
});

// Cancel the loading prompt after 60 seconds
setTimeout(() => {
if (this.waitingForClientToken) {
this.clearWaitingToken();

vscode.window.showErrorMessage(
"Select PowerShell Host Process to attach to: PowerShell session took too long to start.");
"Attach to PowerShell host process: PowerShell session took too long to start.");
}
}, 60000);

// Wait w/timeout on language client to be initialized and then return this.pickPSHostProcess;
}
else {
return this.pickPSHostProcess();
Expand All @@ -105,7 +114,7 @@ export class PickPSHostProcessFeature implements IFeature {

if (this.waitingForClientToken) {
this.clearWaitingToken();
return this.pickPSHostProcess();
// Signal language client initialized
}
}

Expand All @@ -114,37 +123,36 @@ export class PickPSHostProcessFeature implements IFeature {
}

// In node, the function returned a Promise<string> not sure about "Thenable<string>"
private pickPSHostProcess(): Thenable<string> {
return this.languageClient.sendRequest(GetPSHostProcessesRequest.type, null).then(hostProcesses => {
var items: ProcessItem[] = [];

for(var p in hostProcesses) {
items.push({
label: hostProcesses[p].processName,
description: hostProcesses[p].processId.toString(),
detail: hostProcesses[p].mainWindowTitle,
pid: hostProcesses[p].processId
});
};

if (items.length === 0) {
return vscode.window.showInformationMessage(
"There are no other PowerShell host processes to attach to.").then(_ => {
return null;
private pickPSHostProcess(): Promise<string> {
return new Promise((resolve, reject) => {
this.languageClient.sendRequest(GetPSHostProcessesRequest.type, null).then(hostProcesses => {
var items: ProcessItem[] = [];

for(var p in hostProcesses) {
items.push({
label: hostProcesses[p].processName,
description: hostProcesses[p].processId.toString(),
detail: hostProcesses[p].mainWindowTitle,
pid: hostProcesses[p].processId
});
}
else {
let options : vscode.QuickPickOptions = {
placeHolder: "Select a PowerShell Host process to attach to",
matchOnDescription: true,
matchOnDetail: true
};

return vscode.window.showQuickPick(items, options).then(item => {
return item ? item.pid : null;
});
}
});
if (items.length === 0) {
reject("There are no PowerShell host processes to attach to.");
}
else {
let options : vscode.QuickPickOptions = {
placeHolder: "Select a PowerShell host process to attach to",
matchOnDescription: true,
matchOnDetail: true
};

return vscode.window.showQuickPick(items, options).then(item => {
resolve(item ? item.pid : "");
});
}
});
});
}

private clearWaitingToken() {
Expand Down