Skip to content

Commit c9390bf

Browse files
committed
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.
1 parent 2399e15 commit c9390bf

File tree

2 files changed

+47
-38
lines changed

2 files changed

+47
-38
lines changed

package.json

Lines changed: 7 additions & 6 deletions
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

Lines changed: 40 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,32 @@ export class PickPSHostProcessFeature implements IFeature {
7676

7777
// If PowerShell isn't finished loading yet, show a loading message
7878
// until the LanguageClient is passed on to us
79+
var cancelled = false;
80+
var timedOut = false;
7981
this.waitingForClientToken = new vscode.CancellationTokenSource();
82+
8083
vscode.window
8184
.showQuickPick(
8285
["Cancel"],
83-
{ placeHolder: "Select PowerShell Host Process to attach to: Please wait, starting PowerShell..." },
86+
{ placeHolder: "Attach to PowerShell host process: Please wait, starting PowerShell..." },
8487
this.waitingForClientToken.token)
85-
.then(response => { if (response === "Cancel") { this.clearWaitingToken(); } });
88+
.then(response => {
89+
if (response === "Cancel") {
90+
this.clearWaitingToken();
91+
}
92+
});
8693

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

9299
vscode.window.showErrorMessage(
93-
"Select PowerShell Host Process to attach to: PowerShell session took too long to start.");
100+
"Attach to PowerShell host process: PowerShell session took too long to start.");
94101
}
95102
}, 60000);
103+
104+
// Wait w/timeout on language client to be initialized and then return this.pickPSHostProcess;
96105
}
97106
else {
98107
return this.pickPSHostProcess();
@@ -105,7 +114,7 @@ export class PickPSHostProcessFeature implements IFeature {
105114

106115
if (this.waitingForClientToken) {
107116
this.clearWaitingToken();
108-
return this.pickPSHostProcess();
117+
// Signal language client initialized
109118
}
110119
}
111120

@@ -114,37 +123,36 @@ export class PickPSHostProcessFeature implements IFeature {
114123
}
115124

116125
// 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;
126+
private pickPSHostProcess(): Promise<string> {
127+
return new Promise((resolve, reject) => {
128+
this.languageClient.sendRequest(GetPSHostProcessesRequest.type, null).then(hostProcesses => {
129+
var items: ProcessItem[] = [];
130+
131+
for(var p in hostProcesses) {
132+
items.push({
133+
label: hostProcesses[p].processName,
134+
description: hostProcesses[p].processId.toString(),
135+
detail: hostProcesses[p].mainWindowTitle,
136+
pid: hostProcesses[p].processId
134137
});
135-
}
136-
else {
137-
let options : vscode.QuickPickOptions = {
138-
placeHolder: "Select a PowerShell Host process to attach to",
139-
matchOnDescription: true,
140-
matchOnDetail: true
141138
};
142139

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

150158
private clearWaitingToken() {

0 commit comments

Comments
 (0)