From c9390bf36c92abfe9d89650367af98ac5f8b440e Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sun, 15 Jan 2017 21:21:56 -0700 Subject: [PATCH 1/2] Fix host process picker when session init'd. Also fix the "initialConfigurations" attach setting to use the host process picker and set a default runspaceId. --- package.json | 13 ++++--- src/features/DebugSession.ts | 72 ++++++++++++++++++++---------------- 2 files changed, 47 insertions(+), 38 deletions(-) diff --git a/package.json b/package.json index de3f68e6c7..04f1b2b155 100644 --- a/package.json +++ b/package.json @@ -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 } @@ -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": { @@ -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", diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 521e9e0fe2..0a48429adf 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -76,13 +76,20 @@ 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(() => { @@ -90,9 +97,11 @@ export class PickPSHostProcessFeature implements IFeature { 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(); @@ -105,7 +114,7 @@ export class PickPSHostProcessFeature implements IFeature { if (this.waitingForClientToken) { this.clearWaitingToken(); - return this.pickPSHostProcess(); + // Signal language client initialized } } @@ -114,37 +123,36 @@ export class PickPSHostProcessFeature implements IFeature { } // In node, the function returned a Promise not sure about "Thenable" - private pickPSHostProcess(): Thenable { - 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 { + 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() { From c6f4498d27d8ac1344c4113e83e489d550fd5092 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Mon, 16 Jan 2017 23:09:35 -0700 Subject: [PATCH 2/2] If PowerShell has not fully initialized then err. Tell user to try again after PowerShell has fully initialized. This is not an ideal user experience but it is better than the current experience. --- src/features/DebugSession.ts | 59 +++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 0a48429adf..717192306b 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -73,35 +73,38 @@ export class PickPSHostProcessFeature implements IFeature { vscode.commands.registerCommand('PowerShell.PickPSHostProcess', () => { if (!this.languageClient && !this.waitingForClientToken) { + return new Promise((resolve, reject) => { + reject("PowerShell has not fully initialized. Try to attach again after PowerShell has been initialized."); + }); - // 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: "Attach to PowerShell host process: Please wait, starting PowerShell..." }, - this.waitingForClientToken.token) - .then(response => { - if (response === "Cancel") { - this.clearWaitingToken(); - } - }); - - // Cancel the loading prompt after 60 seconds - setTimeout(() => { - if (this.waitingForClientToken) { - this.clearWaitingToken(); - - vscode.window.showErrorMessage( - "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; + // // 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: "Attach to PowerShell host process: Please wait, starting PowerShell..." }, + // this.waitingForClientToken.token) + // .then(response => { + // if (response === "Cancel") { + // this.clearWaitingToken(); + // } + // }); + + // // Cancel the loading prompt after 60 seconds + // setTimeout(() => { + // if (this.waitingForClientToken) { + // this.clearWaitingToken(); + + // vscode.window.showErrorMessage( + // "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();