Skip to content

Commit 1352177

Browse files
committed
WIP: first pass at PowerShell#1611 - provide dynamic debug config
1 parent 41470bc commit 1352177

File tree

2 files changed

+95
-69
lines changed

2 files changed

+95
-69
lines changed

package.json

+8-65
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
"main": "./out/src/main",
2929
"activationEvents": [
30+
"onDebugInitialConfigurations",
3031
"onDebugResolve:powershell",
3132
"onLanguage:powershell",
3233
"onCommand:PowerShell.NewProjectFromTemplate",
@@ -66,6 +67,11 @@
6667
"test": "node ./node_modules/vscode/bin/test"
6768
},
6869
"contributes": {
70+
"breakpoints": [
71+
{
72+
"language": "powershell"
73+
}
74+
],
6975
"viewsContainers": {
7076
"activitybar": [
7177
{
@@ -311,11 +317,6 @@
311317
{
312318
"type": "PowerShell",
313319
"label": "PowerShell",
314-
"enableBreakpointsFor": {
315-
"languageIds": [
316-
"powershell"
317-
]
318-
},
319320
"program": "./out/src/debugAdapter.js",
320321
"runtime": "node",
321322
"variables": {
@@ -339,19 +340,6 @@
339340
"cwd": "^\"\\${file}\""
340341
}
341342
},
342-
{
343-
"label": "PowerShell: Launch Current File in Temporary Console",
344-
"description": "Launch current file (in active editor window) under debugger in a temporary Integrated Console.",
345-
"body": {
346-
"name": "PowerShell Launch Current File in Temporary Console",
347-
"type": "PowerShell",
348-
"request": "launch",
349-
"script": "^\"\\${file}\"",
350-
"args": [],
351-
"cwd": "^\"\\${file}\"",
352-
"createTemporaryIntegratedConsole": true
353-
}
354-
},
355343
{
356344
"label": "PowerShell: Launch Current File w/Args Prompt",
357345
"description": "Launch current file (in active editor window) under debugger, prompting first for script arguments",
@@ -430,7 +418,7 @@
430418
},
431419
"args": {
432420
"type": "array",
433-
"description": "Command line arguments to pass to the PowerShell script.",
421+
"description": "Command line arguments to pass to the PowerShell script. Specify ${command:SpecifyScriptArgs} if you want to be prompted for the args.",
434422
"items": {
435423
"type": "string"
436424
},
@@ -480,52 +468,7 @@
480468
}
481469
}
482470
},
483-
"initialConfigurations": [
484-
{
485-
"name": "PowerShell Launch Current File",
486-
"type": "PowerShell",
487-
"request": "launch",
488-
"script": "${file}",
489-
"args": [],
490-
"cwd": "${file}"
491-
},
492-
{
493-
"name": "PowerShell Launch Current File in Temporary Console",
494-
"type": "PowerShell",
495-
"request": "launch",
496-
"script": "${file}",
497-
"args": [],
498-
"cwd": "${file}",
499-
"createTemporaryIntegratedConsole": true
500-
},
501-
{
502-
"name": "PowerShell Launch Current File w/Args Prompt",
503-
"type": "PowerShell",
504-
"request": "launch",
505-
"script": "${file}",
506-
"args": [
507-
"${command:SpecifyScriptArgs}"
508-
],
509-
"cwd": "${file}"
510-
},
511-
{
512-
"name": "PowerShell Attach to Host Process",
513-
"type": "PowerShell",
514-
"request": "attach"
515-
},
516-
{
517-
"name": "PowerShell Interactive Session",
518-
"type": "PowerShell",
519-
"request": "launch",
520-
"cwd": ""
521-
},
522-
{
523-
"name": "PowerShell Attach Interactive Session Runspace",
524-
"type": "PowerShell",
525-
"request": "attach",
526-
"processId": "current"
527-
}
528-
]
471+
"initialConfigurations": []
529472
}
530473
],
531474
"configuration": {

src/features/DebugSession.ts

+87-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
* Copyright (C) Microsoft Corporation. All rights reserved.
33
*--------------------------------------------------------*/
44

5+
import path = require("path");
56
import vscode = require("vscode");
67
import { CancellationToken, DebugConfiguration, DebugConfigurationProvider,
7-
ExtensionContext, ProviderResult, WorkspaceFolder } from "vscode";
8+
ExtensionContext, WorkspaceFolder } from "vscode";
89
import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient";
910
import { IFeature } from "../feature";
1011
import { getPlatformDetails, OperatingSystem } from "../platform";
@@ -42,6 +43,88 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
4243
}));
4344
}
4445

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+
45128
// DebugConfigurationProvider method
46129
public async resolveDebugConfiguration(
47130
folder: WorkspaceFolder | undefined,
@@ -161,13 +244,13 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
161244
}
162245

163246
if ((currentDocument.languageId !== "powershell") || !isValidExtension) {
164-
let path = currentDocument.fileName;
247+
let docPath = currentDocument.fileName;
165248
const workspaceRootPath = vscode.workspace.rootPath;
166249
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);
168251
}
169252

170-
const msg = "PowerShell does not support debugging this file type: '" + path + "'.";
253+
const msg = "PowerShell does not support debugging this file type: '" + docPath + "'.";
171254
vscode.window.showErrorMessage(msg);
172255
return;
173256
}

0 commit comments

Comments
 (0)