Skip to content

Commit d84582b

Browse files
authored
Merge pull request #437 from rkeithhill/rkeithhill/process-pick-handle-no-selection
Fix host process picker when session init'd.
2 parents 37ad0e3 + c6f4498 commit d84582b

File tree

2 files changed

+66
-54
lines changed

2 files changed

+66
-54
lines changed

package.json

+7-6
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@
196196
}
197197
},
198198
{
199-
"label": "PowerShell: Attach to PowerShell Process Configuration",
200-
"description": "A new configuration for debugging a runspace in another process.",
199+
"label": "PowerShell: Attach to PowerShell Host Process Configuration",
200+
"description": "A new configuration for debugging a runspace in another host process.",
201201
"body": {
202202
"type": "PowerShell",
203203
"request": "attach",
204-
"name": "PowerShell Attach to Process",
204+
"name": "PowerShell Attach to Host Process",
205205
"processId": "^\"\\${command.PickPSHostProcess}\"",
206206
"runspaceId": 1
207207
}
@@ -251,7 +251,7 @@
251251
},
252252
"processId": {
253253
"type": "string",
254-
"description": "Id of PowerShell host process to attach to. Works only on PowerShell 5 and above.",
254+
"description": "The process id of the PowerShell host process to attach to. Works only on PowerShell 5 and above.",
255255
"default": "${command.PickPSHostProcess}"
256256
},
257257
"runspaceId": {
@@ -274,8 +274,9 @@
274274
{
275275
"type": "PowerShell",
276276
"request": "attach",
277-
"name": "PowerShell Attach",
278-
"processId": "12345"
277+
"name": "PowerShell Attach to Host Process",
278+
"processId": "${command.PickPSHostProcess}",
279+
"runspaceId": 1
279280
},
280281
{
281282
"type": "PowerShell",

src/features/DebugSession.ts

+59-48
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,38 @@ export class PickPSHostProcessFeature implements IFeature {
7373
vscode.commands.registerCommand('PowerShell.PickPSHostProcess', () => {
7474

7575
if (!this.languageClient && !this.waitingForClientToken) {
76+
return new Promise<string>((resolve, reject) => {
77+
reject("PowerShell has not fully initialized. Try to attach again after PowerShell has been initialized.");
78+
});
7679

77-
// If PowerShell isn't finished loading yet, show a loading message
78-
// until the LanguageClient is passed on to us
79-
this.waitingForClientToken = new vscode.CancellationTokenSource();
80-
vscode.window
81-
.showQuickPick(
82-
["Cancel"],
83-
{ placeHolder: "Select PowerShell Host Process to attach to: Please wait, starting PowerShell..." },
84-
this.waitingForClientToken.token)
85-
.then(response => { if (response === "Cancel") { this.clearWaitingToken(); } });
86-
87-
// Cancel the loading prompt after 60 seconds
88-
setTimeout(() => {
89-
if (this.waitingForClientToken) {
90-
this.clearWaitingToken();
91-
92-
vscode.window.showErrorMessage(
93-
"Select PowerShell Host Process to attach to: PowerShell session took too long to start.");
94-
}
95-
}, 60000);
80+
// // If PowerShell isn't finished loading yet, show a loading message
81+
// // until the LanguageClient is passed on to us
82+
// var cancelled = false;
83+
// var timedOut = false;
84+
// this.waitingForClientToken = new vscode.CancellationTokenSource();
85+
86+
// vscode.window
87+
// .showQuickPick(
88+
// ["Cancel"],
89+
// { placeHolder: "Attach to PowerShell host process: Please wait, starting PowerShell..." },
90+
// this.waitingForClientToken.token)
91+
// .then(response => {
92+
// if (response === "Cancel") {
93+
// this.clearWaitingToken();
94+
// }
95+
// });
96+
97+
// // Cancel the loading prompt after 60 seconds
98+
// setTimeout(() => {
99+
// if (this.waitingForClientToken) {
100+
// this.clearWaitingToken();
101+
102+
// vscode.window.showErrorMessage(
103+
// "Attach to PowerShell host process: PowerShell session took too long to start.");
104+
// }
105+
// }, 60000);
106+
107+
// // Wait w/timeout on language client to be initialized and then return this.pickPSHostProcess;
96108
}
97109
else {
98110
return this.pickPSHostProcess();
@@ -105,7 +117,7 @@ export class PickPSHostProcessFeature implements IFeature {
105117

106118
if (this.waitingForClientToken) {
107119
this.clearWaitingToken();
108-
return this.pickPSHostProcess();
120+
// Signal language client initialized
109121
}
110122
}
111123

@@ -114,37 +126,36 @@ export class PickPSHostProcessFeature implements IFeature {
114126
}
115127

116128
// In node, the function returned a Promise<string> not sure about "Thenable<string>"
117-
private pickPSHostProcess(): Thenable<string> {
118-
return this.languageClient.sendRequest(GetPSHostProcessesRequest.type, null).then(hostProcesses => {
119-
var items: ProcessItem[] = [];
120-
121-
for(var p in hostProcesses) {
122-
items.push({
123-
label: hostProcesses[p].processName,
124-
description: hostProcesses[p].processId.toString(),
125-
detail: hostProcesses[p].mainWindowTitle,
126-
pid: hostProcesses[p].processId
127-
});
128-
};
129-
130-
if (items.length === 0) {
131-
return vscode.window.showInformationMessage(
132-
"There are no other PowerShell host processes to attach to.").then(_ => {
133-
return null;
129+
private pickPSHostProcess(): Promise<string> {
130+
return new Promise((resolve, reject) => {
131+
this.languageClient.sendRequest(GetPSHostProcessesRequest.type, null).then(hostProcesses => {
132+
var items: ProcessItem[] = [];
133+
134+
for(var p in hostProcesses) {
135+
items.push({
136+
label: hostProcesses[p].processName,
137+
description: hostProcesses[p].processId.toString(),
138+
detail: hostProcesses[p].mainWindowTitle,
139+
pid: hostProcesses[p].processId
134140
});
135-
}
136-
else {
137-
let options : vscode.QuickPickOptions = {
138-
placeHolder: "Select a PowerShell Host process to attach to",
139-
matchOnDescription: true,
140-
matchOnDetail: true
141141
};
142142

143-
return vscode.window.showQuickPick(items, options).then(item => {
144-
return item ? item.pid : null;
145-
});
146-
}
147-
});
143+
if (items.length === 0) {
144+
reject("There are no PowerShell host processes to attach to.");
145+
}
146+
else {
147+
let options : vscode.QuickPickOptions = {
148+
placeHolder: "Select a PowerShell host process to attach to",
149+
matchOnDescription: true,
150+
matchOnDetail: true
151+
};
152+
153+
return vscode.window.showQuickPick(items, options).then(item => {
154+
resolve(item ? item.pid : "");
155+
});
156+
}
157+
});
158+
});
148159
}
149160

150161
private clearWaitingToken() {

0 commit comments

Comments
 (0)