-
Notifications
You must be signed in to change notification settings - Fork 511
/
Copy pathDebugSession.ts
672 lines (569 loc) · 28.4 KB
/
DebugSession.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import {
debug,
CancellationToken,
CancellationTokenSource,
DebugAdapterDescriptor,
DebugAdapterDescriptorFactory,
DebugAdapterExecutable,
DebugAdapterNamedPipeServer,
DebugConfiguration,
DebugConfigurationProvider,
DebugSession,
ExtensionContext,
WorkspaceFolder,
Disposable,
window,
extensions,
workspace,
commands,
InputBoxOptions,
QuickPickItem,
QuickPickOptions,
DebugConfigurationProviderTriggerKind
} from "vscode";
import type { DebugProtocol } from "@vscode/debugprotocol";
import { NotificationType, RequestType } from "vscode-languageclient";
import { LanguageClient } from "vscode-languageclient/node";
import { LanguageClientConsumer } from "../languageClientConsumer";
import { ILogger } from "../logging";
import { OperatingSystem, getPlatformDetails } from "../platform";
import { PowerShellProcess } from "../process";
import { IEditorServicesSessionDetails, SessionManager } from "../session";
import { getSettings } from "../settings";
import path from "path";
import { checkIfFileExists } from "../utils";
export const StartDebuggerNotificationType =
new NotificationType<void>("powerShell/startDebugger");
export const StopDebuggerNotificationType =
new NotificationType<void>("powerShell/stopDebugger");
export enum DebugConfig {
LaunchCurrentFile,
LaunchScript,
InteractiveSession,
AttachHostProcess,
RunPester,
ModuleInteractiveSession,
BinaryModule,
BinaryModulePester,
}
/** Make the implicit behavior of undefined and null in the debug api more explicit */
type PREVENT_DEBUG_START = undefined;
type PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG = null;
type ResolveDebugConfigurationResult = DebugConfiguration | PREVENT_DEBUG_START | PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG;
const PREVENT_DEBUG_START = undefined;
const PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG = null;
/** Represents the various built-in debug configurations that will be advertised to the user if they choose "Add Config" from the launch debug config window */
// NOTE: These are duplicated with what is in package.json until https://github.com/microsoft/vscode/issues/150663#issuecomment-1506134754 is resolved.
export const DebugConfigurations: Record<DebugConfig, DebugConfiguration> = {
[DebugConfig.LaunchCurrentFile]: {
name: "PowerShell: Launch Current File",
type: "PowerShell",
request: "launch",
script: "${file}",
args: [],
},
[DebugConfig.LaunchScript]: {
name: "PowerShell: Launch Script",
type: "PowerShell",
request: "launch",
script: "Enter path or command to execute, for example: \"${workspaceFolder}/src/foo.ps1\" or \"Invoke-Pester\"",
args: [],
},
[DebugConfig.InteractiveSession]: {
name: "PowerShell: Interactive Session",
type: "PowerShell",
request: "launch",
},
[DebugConfig.AttachHostProcess]: {
name: "PowerShell: Attach to PowerShell Host Process",
type: "PowerShell",
request: "attach",
},
[DebugConfig.RunPester]: {
name: "PowerShell: Run Pester Tests",
type: "PowerShell",
request: "launch",
script: "Invoke-Pester",
createTemporaryIntegratedConsole: true,
attachDotnetDebugger: true,
},
[DebugConfig.ModuleInteractiveSession]: {
name: "PowerShell: Module Interactive Session",
type: "PowerShell",
request: "launch",
script: "Enter command to import your binary module, for example: \"Import-Module -Force ${workspaceFolder}/path/to/module.psd1|dll\"",
},
[DebugConfig.BinaryModule]: {
name: "PowerShell: Binary Module Interactive",
type: "PowerShell",
request: "launch",
script: "Enter command to import your binary module, for example: \"Import-Module -Force ${workspaceFolder}/path/to/module.psd1|dll\"",
createTemporaryIntegratedConsole: true,
attachDotnetDebugger: true,
},
[DebugConfig.BinaryModulePester]: {
name: "PowerShell: Binary Module Pester Tests",
type: "PowerShell",
request: "launch",
script: "Invoke-Pester",
createTemporaryIntegratedConsole: true,
attachDotnetDebugger: true,
}
};
export class DebugSessionFeature extends LanguageClientConsumer
implements DebugConfigurationProvider, DebugAdapterDescriptorFactory {
private tempDebugProcess: PowerShellProcess | undefined;
private tempSessionDetails: IEditorServicesSessionDetails | undefined;
private commands: Disposable[] = [];
private handlers: Disposable[] = [];
constructor(context: ExtensionContext, private sessionManager: SessionManager, private logger: ILogger) {
super();
this.activateDebugAdaptor(context);
// NOTE: While process and runspace IDs are numbers, command
// substitutions in VS Code debug configurations are required to return
// strings. Hence to the `toString()` on these.
this.commands = [
commands.registerCommand("PowerShell.PickPSHostProcess", async () => {
const processId = await this.pickPSHostProcess();
return processId?.toString();
}),
commands.registerCommand("PowerShell.PickRunspace", async (processId) => {
const runspace = await this.pickRunspace(processId);
return runspace?.toString();
}, this),
];
}
public dispose(): void {
for (const command of this.commands) {
command.dispose();
}
for (const handler of this.handlers) {
handler.dispose();
}
}
// This "activates" the debug adapter. You can only do this once.
public activateDebugAdaptor(context: ExtensionContext): void {
const triggers = [
DebugConfigurationProviderTriggerKind.Initial,
DebugConfigurationProviderTriggerKind.Dynamic
];
for (const triggerKind of triggers) {
context.subscriptions.push(
debug.registerDebugConfigurationProvider("PowerShell", this, triggerKind));
}
context.subscriptions.push(debug.registerDebugAdapterDescriptorFactory("PowerShell", this));
}
public override onLanguageClientSet(languageClient: LanguageClient): void {
this.handlers = [
languageClient.onNotification(
StartDebuggerNotificationType,
() => void debug.startDebugging(undefined, DebugConfigurations[DebugConfig.InteractiveSession])),
languageClient.onNotification(
StopDebuggerNotificationType,
() => void debug.stopDebugging(undefined))
];
}
public async provideDebugConfigurations(
_folder: WorkspaceFolder | undefined,
_token?: CancellationToken): Promise<DebugConfiguration[]> {
const debugConfigPickItems = [
{
id: DebugConfig.LaunchCurrentFile,
label: "Launch Current File",
description: "Launch and debug the file in the currently active editor window",
},
{
id: DebugConfig.LaunchScript,
label: "Launch Script",
description: "Launch and debug the specified file or command",
},
{
id: DebugConfig.InteractiveSession,
label: "Interactive Session",
description: "Debug commands executed from the PowerShell Extension Terminal",
},
{
id: DebugConfig.AttachHostProcess,
label: "Attach",
description: "Attach the debugger to a running PowerShell Host Process",
},
{
id: DebugConfig.RunPester,
label: "Run Pester Tests",
description: "Debug Pester Tests detected in your current directory (runs Invoke-Pester)",
},
{
id: DebugConfig.ModuleInteractiveSession,
label: "Interactive Session (Module)",
description: "Debug commands executed from the PowerShell Extension Terminal after auto-loading your module",
},
{
id: DebugConfig.BinaryModule,
label: "Interactive Session (Binary Module)",
description: "Debug a .NET binary or hybrid module loaded into a PowerShell session. Breakpoints you set in your .NET (C#/F#/VB/etc.) code will be hit upon command execution. You may want to add a compile or watch action as a pre-launch task to this configuration.",
},
{
id: DebugConfig.RunPester,
label: "Run Pester Tests (Binary Module)",
description: "Debug a .NET binary or hybrid module by running Pester tests. Breakpoints you set in your .NET (C#/F#/VB/etc.) code will be hit upon command execution. You may want to add a compile or watch action as a pre-launch task to this configuration.",
},
];
const launchSelection =
await window.showQuickPick(
debugConfigPickItems,
{ placeHolder: "Select a PowerShell debug configuration" });
if (launchSelection) {
return [DebugConfigurations[launchSelection.id]];
}
return [DebugConfigurations[DebugConfig.LaunchCurrentFile]];
}
// We don't use await here but we are returning a promise and the return syntax is easier in an async function
// eslint-disable-next-line @typescript-eslint/require-await
public async resolveDebugConfiguration(
_folder: WorkspaceFolder | undefined,
config: DebugConfiguration,
_token?: CancellationToken): Promise<ResolveDebugConfigurationResult> {
// NOTE: We intentionally do not touch the `cwd` setting of the config.
if (!config.request) {
// No launch.json, create the default configuration for both unsaved
// (Untitled) and saved documents.
const LaunchCurrentFileConfig = DebugConfigurations[DebugConfig.LaunchCurrentFile];
config = { ...config, ...LaunchCurrentFileConfig };
config.current_document = true;
}
if (config.script === "${file}" || config.script === "${relativeFile}") {
if (window.activeTextEditor === undefined) {
void this.logger.writeAndShowError("To debug the 'Current File', you must first open a PowerShell script file in the editor.");
return PREVENT_DEBUG_START;
}
config.current_document = true;
// Special case using the URI for untitled documents.
const currentDocument = window.activeTextEditor.document;
if (currentDocument.isUntitled) {
config.untitled_document = true;
config.script = currentDocument.uri.toString();
}
}
return config;
}
public async resolveDebugConfigurationWithSubstitutedVariables(
_folder: WorkspaceFolder | undefined,
config: DebugConfiguration,
_token?: CancellationToken): Promise<ResolveDebugConfigurationResult> {
let resolvedConfig: ResolveDebugConfigurationResult;
// Prevent the Debug Console from opening
config.internalConsoleOptions = "neverOpen";
const settings = getSettings();
config.createTemporaryIntegratedConsole ??= settings.debugging.createTemporaryIntegratedConsole;
config.executeMode ??= settings.debugging.executeMode;
if (config.request === "attach") {
resolvedConfig = await this.resolveAttachDebugConfiguration(config);
} else if (config.request === "launch") {
resolvedConfig = await this.resolveLaunchDebugConfiguration(config);
} else {
void this.logger.writeAndShowError(`PowerShell debug configuration's request type was invalid: '${config.request}'.`);
return PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG;
}
return resolvedConfig;
}
// This is our factory entrypoint hook to when a debug session starts, and
// where we will lazy initialize everything needed to do the debugging such
// as a temporary console if required.
//
// NOTE: A Promise meets the shape of a ProviderResult, which allows us to
// make this method async.
public async createDebugAdapterDescriptor(
session: DebugSession,
_executable: DebugAdapterExecutable | undefined): Promise<DebugAdapterDescriptor | undefined> {
await this.sessionManager.start();
const sessionDetails = session.configuration.createTemporaryIntegratedConsole
? await this.createTemporaryIntegratedConsole(session)
: this.sessionManager.getSessionDetails();
if (sessionDetails === undefined) {
return undefined;
}
// Create or show the debug terminal (either temporary or session).
this.sessionManager.showDebugTerminal(true);
this.logger.writeVerbose(`Connecting to pipe: ${sessionDetails.debugServicePipeName}`);
this.logger.writeVerbose(`Debug configuration: ${JSON.stringify(session.configuration, undefined, 2)}`);
return new DebugAdapterNamedPipeServer(sessionDetails.debugServicePipeName);
}
private async resolveLaunchDebugConfiguration(config: DebugConfiguration): Promise<ResolveDebugConfigurationResult> {
// Check the languageId and file extension only for current documents
// (which includes untitled documents). This prevents accidentally
// running the debugger for an open non-PowerShell file.
if (config.current_document) {
const currentDocument = window.activeTextEditor?.document;
if (currentDocument?.languageId !== "powershell") {
void this.logger.writeAndShowError(`PowerShell does not support debugging this language mode: '${currentDocument?.languageId}'.`);
return PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG;
}
if (await checkIfFileExists(config.script)) {
const ext = path.extname(config.script).toLowerCase();
if (!(ext === ".ps1" || ext === ".psm1")) {
void this.logger.writeAndShowError(`PowerShell does not support debugging this file type: '${path.basename(config.script)}'.`);
return PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG;
}
}
}
if (config.untitled_document && config.createTemporaryIntegratedConsole) {
void this.logger.writeAndShowError("PowerShell does not support debugging untitled files in a temporary console.");
return PREVENT_DEBUG_START;
}
if (!config.createTemporaryIntegratedConsole && config.attachDotnetDebugger) {
void this.logger.writeAndShowError("dotnet debugging without using a temporary console is currently not supported. Please updated your launch config to include createTemporaryIntegratedConsole: true.");
return PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG;
}
if (config.attachDotnetDebugger) {
return this.resolveAttachDotnetDebugConfiguration(config);
}
return config;
}
private resolveAttachDotnetDebugConfiguration(config: DebugConfiguration): ResolveDebugConfigurationResult {
if (!extensions.getExtension("ms-dotnettools.csharp")) {
void this.logger.writeAndShowError("You specified attachDotnetDebugger in your PowerShell Launch configuration but the C# extension is not installed. Please install the C# extension and try again.");
return PREVENT_DEBUG_START;
}
const dotnetDebuggerConfig = this.getDotnetNamedConfigOrDefault(config.dotnetDebuggerConfigName);
if (dotnetDebuggerConfig === undefined) {
void this.logger.writeAndShowError(`You specified dotnetDebuggerConfigName in your PowerShell Launch configuration but a matching launch config was not found. Please ensure you have a coreclr attach config with the name ${config.dotnetDebuggerConfigName} in your launch.json file or remove dotnetDebuggerConfigName from your PowerShell Launch configuration to use the defaults`);
return PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG;
}
config.dotnetAttachConfig = dotnetDebuggerConfig;
return config;
}
private async createTemporaryIntegratedConsole(session: DebugSession): Promise<IEditorServicesSessionDetails | undefined> {
const settings = getSettings();
this.tempDebugProcess = await this.sessionManager.createDebugSessionProcess(settings);
// TODO: Maybe set a timeout on the cancellation token?
const cancellationTokenSource = new CancellationTokenSource();
this.tempSessionDetails = await this.tempDebugProcess.start(cancellationTokenSource.token);
// NOTE: Dotnet attach debugging is only currently supported if a temporary debug terminal is used, otherwise we get lots of lock conflicts from loading the assemblies.
if (session.configuration.attachDotnetDebugger) {
const dotnetAttachConfig = session.configuration.dotnetAttachConfig;
// Will wait until the process is started and available before attaching
const pid = await this.tempDebugProcess.getPid();
if (pid === undefined) {
void this.logger.writeAndShowError("Attach Dotnet Debugger was specified but the PowerShell temporary debug session failed to start. This is probably a bug.");
return PREVENT_DEBUG_START;
}
dotnetAttachConfig.processId = pid;
// Ensure the .NET session stops before the PowerShell session so that the .NET debug session doesn't emit an error about the process unexpectedly terminating.
let tempConsoleDotnetAttachSession: DebugSession;
const startDebugEvent = debug.onDidStartDebugSession(dotnetAttachSession => {
if (dotnetAttachSession.configuration.name != dotnetAttachConfig.name) { return; }
// Makes the event one-time
// HACK: This seems like you would be calling a method on a variable not assigned yet, but it does work in the flow.
// The dispose shorthand demonry for making an event one-time courtesy of: https://github.com/OmniSharp/omnisharp-vscode/blob/b8b07bb12557b4400198895f82a94895cb90c461/test/integrationTests/launchConfiguration.integration.test.ts#L41-L45
startDebugEvent.dispose();
this.logger.writeVerbose(`Debugger session detected: ${dotnetAttachSession.name} (${dotnetAttachSession.id})`);
tempConsoleDotnetAttachSession = dotnetAttachSession;
const stopDebugEvent = debug.onDidTerminateDebugSession(async tempConsoleSession => {
if (tempConsoleDotnetAttachSession.parentSession?.id !== tempConsoleSession.id) { return; }
// Makes the event one-time
stopDebugEvent.dispose();
this.logger.writeVerbose(`Debugger session terminated: ${tempConsoleSession.name} (${tempConsoleSession.id})`);
// HACK: As of 2023-08-17, there is no vscode debug API to request the C# debugger to detach, so we send it a custom DAP request instead.
const disconnectRequest: DebugProtocol.DisconnectRequest = {
command: "disconnect",
seq: 0,
type: "request",
arguments: {
restart: false,
terminateDebuggee: false,
suspendDebuggee: false
}
};
try {
await dotnetAttachSession.customRequest(
disconnectRequest.command,
disconnectRequest.arguments
);
} catch (err) {
this.logger.writeWarning(`Disconnect request to dotnet debugger failed: ${err}`);
}
});
});
// Start a child debug session to attach the dotnet debugger
// TODO: Accommodate multi-folder workspaces if the C# code is in a different workspace folder
await debug.startDebugging(undefined, dotnetAttachConfig, session);
this.logger.writeVerbose(`Dotnet attach debug configuration: ${JSON.stringify(dotnetAttachConfig, undefined, 2)}`);
this.logger.writeVerbose(`Attached dotnet debugger to process: ${pid}`);
}
return this.tempSessionDetails;
}
private getDotnetNamedConfigOrDefault(configName?: string): ResolveDebugConfigurationResult {
if (configName) {
const debugConfigs = this.getLaunchConfigurations();
return debugConfigs.find(({ type, request, name }) =>
type === "coreclr" &&
request === "attach" &&
name === configName
);
}
// Default debugger config if none provided
// TODO: Type this appropriately from the C# extension?
return {
name: "Dotnet Debugger: Temporary Extension Terminal",
type: "coreclr",
request: "attach",
processId: undefined,
logging: {
moduleLoad: false
}
};
}
/** Fetches all available vscode launch configurations. This is abstracted out for easier testing. */
private getLaunchConfigurations(): DebugConfiguration[] {
return workspace.getConfiguration("launch").get<DebugConfiguration[]>("configurations") ?? [];
}
private async resolveAttachDebugConfiguration(config: DebugConfiguration): Promise<ResolveDebugConfigurationResult> {
const platformDetails = getPlatformDetails();
const versionDetails = this.sessionManager.getPowerShellVersionDetails();
if (versionDetails === undefined) {
void this.logger.writeAndShowError(`PowerShell session version details were not found for '${config.name}'.`);
return PREVENT_DEBUG_START;
}
// Cross-platform attach to process was added in 6.2.0-preview.4.
if (versionDetails.version < "7.0.0" && platformDetails.operatingSystem !== OperatingSystem.Windows) {
void this.logger.writeAndShowError(`Attaching to a PowerShell Host Process on ${OperatingSystem[platformDetails.operatingSystem]} requires PowerShell 7.0 or higher (Current Version: ${versionDetails.version}).`);
return PREVENT_DEBUG_START;
}
// If nothing is set, prompt for the processId.
if (!config.customPipeName && !config.processId) {
config.processId = await this.pickPSHostProcess();
// No process selected. Cancel attach.
if (!config.processId) {
return PREVENT_DEBUG_START;
}
}
// If we were given a stringified int from the user, or from the picker
// command, we need to parse it here.
if (typeof config.processId === "string" && config.processId != "current") {
config.processId = parseInt(config.processId);
}
// NOTE: We don't support attaching to the Extension Terminal, even
// though in the past it looked like we did. The implementation was
// half-baked and left things unusable.
if (config.processId === "current" || config.processId === await this.sessionManager.getLanguageServerPid()) {
// TODO: When (if ever) it's supported, we need to convert 0 and the
// old notion of "current" to the actual process ID, like this:
// config.processId = await this.sessionManager.getLanguageServerPid();
void this.logger.writeAndShowError("Attaching to the PowerShell Extension terminal is not supported. Please use the 'PowerShell: Interactive Session' debug configuration instead.");
return PREVENT_DEBUG_START_AND_OPEN_DEBUGCONFIG;
}
if (!config.runspaceId && !config.runspaceName) {
config.runspaceId = await this.pickRunspace(config.processId);
// No runspace selected. Cancel attach.
if (!config.runspaceId) {
return PREVENT_DEBUG_START;
}
}
return config;
}
private async pickPSHostProcess(): Promise<number | undefined> {
const client = await LanguageClientConsumer.getLanguageClient();
const response = await client.sendRequest(GetPSHostProcessesRequestType, {});
const items: IProcessItem[] = [];
for (const process of response) {
let windowTitle = "";
if (process.mainWindowTitle) {
windowTitle = `, ${process.mainWindowTitle}`;
}
items.push({
label: process.processName,
description: `PID: ${process.processId.toString()}${windowTitle}`,
processId: process.processId,
});
}
if (items.length === 0) {
return Promise.reject(new Error("There are no PowerShell host processes to attach."));
}
const options: QuickPickOptions = {
placeHolder: "Select a PowerShell host process to attach.",
matchOnDescription: true,
matchOnDetail: true,
};
const item = await window.showQuickPick(items, options);
return item?.processId ?? undefined;
}
private async pickRunspace(processId: number): Promise<number | undefined> {
const client = await LanguageClientConsumer.getLanguageClient();
const response = await client.sendRequest(GetRunspaceRequestType, { processId });
const items: IRunspaceItem[] = [];
for (const runspace of response) {
items.push({
label: runspace.name,
description: `ID: ${runspace.id} - ${runspace.availability}`,
id: runspace.id,
});
}
const options: QuickPickOptions = {
placeHolder: "Select PowerShell runspace to debug",
matchOnDescription: true,
matchOnDetail: true,
};
const item = await window.showQuickPick(items, options);
return item?.id ?? undefined;
}
}
export class SpecifyScriptArgsFeature implements Disposable {
private command: Disposable;
private context: ExtensionContext;
constructor(context: ExtensionContext) {
this.context = context;
this.command = commands.registerCommand("PowerShell.SpecifyScriptArgs", () => {
return this.specifyScriptArguments();
});
}
public dispose(): void {
this.command.dispose();
}
private async specifyScriptArguments(): Promise<string | undefined> {
const powerShellDbgScriptArgsKey = "powerShellDebugScriptArgs";
const options: InputBoxOptions = {
ignoreFocusOut: true,
placeHolder: "Enter script arguments or leave empty to pass no args",
};
const prevArgs = this.context.workspaceState.get(powerShellDbgScriptArgsKey, "");
if (prevArgs.length > 0) {
options.value = prevArgs;
}
const text = await window.showInputBox(options);
// When user cancel's the input box (by pressing Esc), the text value is undefined.
// Let's not blow away the previous setting.
if (text !== undefined) {
await this.context.workspaceState.update(powerShellDbgScriptArgsKey, text);
}
return text;
}
}
interface IProcessItem extends QuickPickItem {
processId: number; // payload for the QuickPick UI
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface IGetPSHostProcessesArguments {
}
interface IPSHostProcessInfo {
processName: string;
processId: number;
appDomainName: string;
mainWindowTitle: string;
}
export const GetPSHostProcessesRequestType =
new RequestType<IGetPSHostProcessesArguments, IPSHostProcessInfo[], string>("powerShell/getPSHostProcesses");
interface IRunspaceItem extends QuickPickItem {
id: number; // payload for the QuickPick UI
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface IGetRunspaceRequestArguments {
}
interface IRunspace {
id: number;
name: string;
availability: string;
}
export const GetRunspaceRequestType =
new RequestType<IGetRunspaceRequestArguments, IRunspace[], string>("powerShell/getRunspace");