|
2 | 2 | * Copyright (C) Microsoft Corporation. All rights reserved.
|
3 | 3 | *--------------------------------------------------------*/
|
4 | 4 |
|
| 5 | +import path = require("path"); |
5 | 6 | import vscode = require("vscode");
|
6 | 7 | import { CancellationToken, DebugConfiguration, DebugConfigurationProvider,
|
7 |
| - ExtensionContext, ProviderResult, WorkspaceFolder } from "vscode"; |
| 8 | + ExtensionContext, WorkspaceFolder } from "vscode"; |
8 | 9 | import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient";
|
9 | 10 | import { IFeature } from "../feature";
|
10 | 11 | import { getPlatformDetails, OperatingSystem } from "../platform";
|
@@ -42,6 +43,88 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
|
42 | 43 | }));
|
43 | 44 | }
|
44 | 45 |
|
| 46 | + public async provideDebugConfigurations( |
| 47 | + folder: WorkspaceFolder | undefined, |
| 48 | + token?: CancellationToken): Promise<DebugConfiguration[]> { |
| 49 | + |
| 50 | + const launchAttachItems = [ |
| 51 | + { label: "Launch", |
| 52 | + description: "Launch the debugger with a specified script or for the interactive session" }, |
| 53 | + { label: "Attach", |
| 54 | + description: "Attach the debugger to a running PowerShell Host Process" }, |
| 55 | + ]; |
| 56 | + |
| 57 | + const debugTypeSelection = |
| 58 | + await vscode.window.showQuickPick( |
| 59 | + launchAttachItems, |
| 60 | + { placeHolder: "Would you like to launch or attach the PowerShell debugger?" }); |
| 61 | + |
| 62 | + let debugConfiguration = []; |
| 63 | + |
| 64 | + if (debugTypeSelection.label === "Launch") { |
| 65 | + const launchCurrentFileLabel = "Launch Current File"; |
| 66 | + const launchScriptLabel = "Launch Script"; |
| 67 | + const interactiveSessionLabel = "Interactive Session"; |
| 68 | + |
| 69 | + const launchItems = [ |
| 70 | + { label: launchCurrentFileLabel, |
| 71 | + description: "Debugs whichever script is in the active editor window" }, |
| 72 | + { label: launchScriptLabel, |
| 73 | + description: "Debugs the specified script" }, |
| 74 | + { label: interactiveSessionLabel, |
| 75 | + description: "Debugs scripts or modules executed from the Integrated Console" }, |
| 76 | + ]; |
| 77 | + |
| 78 | + const launchSelection = |
| 79 | + await vscode.window.showQuickPick( |
| 80 | + launchItems, |
| 81 | + { placeHolder: "Select a launch option" }); |
| 82 | + |
| 83 | + if (launchSelection.label === launchCurrentFileLabel) { |
| 84 | + debugConfiguration = [ |
| 85 | + { |
| 86 | + name: "PowerShell: Launch Current File", |
| 87 | + type: "PowerShell", |
| 88 | + request: "launch", |
| 89 | + script: "${file}", |
| 90 | + cwd: "${file}", |
| 91 | + }, |
| 92 | + ]; |
| 93 | + } else if (launchSelection.label === launchScriptLabel) { |
| 94 | + debugConfiguration = [ |
| 95 | + { |
| 96 | + name: "PowerShell: Launch Script", |
| 97 | + type: "PowerShell", |
| 98 | + request: "launch", |
| 99 | + script: "enter path or script to execute e.g.: ${workspaceFolder}/src/foo.ps1 or Invoke-Pester", |
| 100 | + cwd: "${workspaceFolder}", |
| 101 | + }, |
| 102 | + ]; |
| 103 | + } else { |
| 104 | + debugConfiguration = [ |
| 105 | + { |
| 106 | + name: "PowerShell: Interactive Session", |
| 107 | + type: "PowerShell", |
| 108 | + request: "launch", |
| 109 | + cwd: "", |
| 110 | + }, |
| 111 | + ]; |
| 112 | + } |
| 113 | + } else { |
| 114 | + // Return the "Attach to PowerShell Host Process" debug configuration |
| 115 | + debugConfiguration = [ |
| 116 | + { |
| 117 | + name: "PowerShell: Attach to PowerShell Host Process", |
| 118 | + type: "PowerShell", |
| 119 | + request: "attach", |
| 120 | + runspaceId: 1, |
| 121 | + }, |
| 122 | + ]; |
| 123 | + } |
| 124 | + |
| 125 | + return debugConfiguration; |
| 126 | + } |
| 127 | + |
45 | 128 | // DebugConfigurationProvider method
|
46 | 129 | public async resolveDebugConfiguration(
|
47 | 130 | folder: WorkspaceFolder | undefined,
|
@@ -161,13 +244,13 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
|
161 | 244 | }
|
162 | 245 |
|
163 | 246 | if ((currentDocument.languageId !== "powershell") || !isValidExtension) {
|
164 |
| - let path = currentDocument.fileName; |
| 247 | + let docPath = currentDocument.fileName; |
165 | 248 | const workspaceRootPath = vscode.workspace.rootPath;
|
166 | 249 | if (currentDocument.fileName.startsWith(workspaceRootPath)) {
|
167 |
| - path = currentDocument.fileName.substring(vscode.workspace.rootPath.length + 1); |
| 250 | + docPath = currentDocument.fileName.substring(vscode.workspace.rootPath.length + 1); |
168 | 251 | }
|
169 | 252 |
|
170 |
| - const msg = "PowerShell does not support debugging this file type: '" + path + "'."; |
| 253 | + const msg = "PowerShell does not support debugging this file type: '" + docPath + "'."; |
171 | 254 | vscode.window.showErrorMessage(msg);
|
172 | 255 | return;
|
173 | 256 | }
|
|
0 commit comments