Skip to content

Commit 1acdee9

Browse files
authored
Implement #1611 - provide dynamic debug config (#2084)
* Address PR comments, change to single promptClean up debug configuration snippet names & descriptions. Remove Launch Pester Tests debug config snippet. The Launch Scriptsnippet gives an example of invoking Pester plus we have code lens to debug Pester tests. * Remove w/Args prompt debug config snippet * Switch to int id check in provideDebugConfig * Address PR feedback, remove path module as it wasn't being used
1 parent 0ad7a06 commit 1acdee9

File tree

2 files changed

+104
-106
lines changed

2 files changed

+104
-106
lines changed

package.json

+17-102
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": {
@@ -329,87 +330,46 @@
329330
"configurationSnippets": [
330331
{
331332
"label": "PowerShell: Launch Current File",
332-
"description": "Launch current file (in active editor window) under debugger",
333+
"description": "Launch and debug the file in the currently active editor window",
333334
"body": {
334335
"name": "PowerShell Launch Current File",
335336
"type": "PowerShell",
336337
"request": "launch",
337338
"script": "^\"\\${file}\"",
338-
"args": [],
339-
"cwd": "^\"\\${file}\""
340-
}
341-
},
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-
},
355-
{
356-
"label": "PowerShell: Launch Current File w/Args Prompt",
357-
"description": "Launch current file (in active editor window) under debugger, prompting first for script arguments",
358-
"body": {
359-
"name": "PowerShell Launch Current File w/Args Prompt",
360-
"type": "PowerShell",
361-
"request": "launch",
362-
"script": "^\"\\${file}\"",
363-
"args": [
364-
"^\"\\${command:SpecifyScriptArgs}\""
365-
],
366339
"cwd": "^\"\\${file}\""
367340
}
368341
},
369342
{
370343
"label": "PowerShell: Launch Script",
371-
"description": "Launch specified script or path to script under debugger",
344+
"description": "Launch and debug the specified file or command",
372345
"body": {
373-
"name": "PowerShell Launch ${Script}",
346+
"name": "PowerShell Launch Script",
374347
"type": "PowerShell",
375348
"request": "launch",
376-
"script": "^\"\\${workspaceFolder}/${Script}\"",
377-
"args": [],
349+
"script": "^\"enter path or command to execute e.g.: \\${workspaceFolder}/src/foo.ps1 or Invoke-Pester\"",
378350
"cwd": "^\"\\${workspaceFolder}\""
379351
}
380352
},
381353
{
382-
"label": "PowerShell: Pester Tests",
383-
"description": "Invokes Pester tests under debugger",
354+
"label": "PowerShell: Interactive Session",
355+
"description": "Debug commands executed from the Integrated Console",
384356
"body": {
385-
"name": "PowerShell Pester Tests",
357+
"name": "PowerShell Interactive Session",
386358
"type": "PowerShell",
387359
"request": "launch",
388-
"script": "Invoke-Pester",
389-
"args": [],
390-
"cwd": "^\"\\${workspaceFolder}\""
360+
"cwd": ""
391361
}
392362
},
393363
{
394364
"label": "PowerShell: Attach to PowerShell Host Process",
395-
"description": "Open host process picker to select process to attach debugger to",
365+
"description": "Attach the debugger to a running PowerShell Host Process",
396366
"body": {
397367
"name": "PowerShell Attach to Host Process",
398368
"type": "PowerShell",
399369
"request": "attach",
400370
"runspaceId": 1
401371
}
402372
},
403-
{
404-
"label": "PowerShell: Interactive Session",
405-
"description": "Start interactive session (Debug Console) under debugger",
406-
"body": {
407-
"name": "PowerShell Interactive Session",
408-
"type": "PowerShell",
409-
"request": "launch",
410-
"cwd": ""
411-
}
412-
},
413373
{
414374
"label": "PowerShell: Attach Interactive Session Runspace",
415375
"description": "Open runspace picker to select runspace to attach debugger to",
@@ -430,7 +390,7 @@
430390
},
431391
"args": {
432392
"type": "array",
433-
"description": "Command line arguments to pass to the PowerShell script.",
393+
"description": "Command line arguments to pass to the PowerShell script. Specify \"${command:SpecifyScriptArgs}\" if you want to be prompted for the args.",
434394
"items": {
435395
"type": "string"
436396
},
@@ -480,52 +440,7 @@
480440
}
481441
}
482442
},
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-
]
443+
"initialConfigurations": []
529444
}
530445
],
531446
"configuration": {

src/features/DebugSession.ts

+87-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import vscode = require("vscode");
66
import { CancellationToken, DebugConfiguration, DebugConfigurationProvider,
7-
ExtensionContext, ProviderResult, WorkspaceFolder } from "vscode";
7+
ExtensionContext, WorkspaceFolder } from "vscode";
88
import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient";
99
import { IFeature } from "../feature";
1010
import { getPlatformDetails, OperatingSystem } from "../platform";
@@ -42,6 +42,89 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
4242
}));
4343
}
4444

45+
public async provideDebugConfigurations(
46+
folder: WorkspaceFolder | undefined,
47+
token?: CancellationToken): Promise<DebugConfiguration[]> {
48+
49+
const launchCurrentFileId = 0;
50+
const launchScriptId = 1;
51+
const interactiveSessionId = 2;
52+
const attachHostProcessId = 3;
53+
54+
const debugConfigPickItems = [
55+
{
56+
id: launchCurrentFileId,
57+
label: "Launch Current File",
58+
description: "Launch and debug the file in the currently active editor window",
59+
},
60+
{
61+
id: launchScriptId,
62+
label: "Launch Script",
63+
description: "Launch and debug the specified file or command",
64+
},
65+
{
66+
id: interactiveSessionId,
67+
label: "Interactive Session",
68+
description: "Debug commands executed from the Integrated Console",
69+
},
70+
{
71+
id: attachHostProcessId,
72+
label: "Attach",
73+
description: "Attach the debugger to a running PowerShell Host Process",
74+
},
75+
];
76+
77+
const launchSelection =
78+
await vscode.window.showQuickPick(
79+
debugConfigPickItems,
80+
{ placeHolder: "Select a PowerShell debug configuration" });
81+
82+
if (launchSelection.id === launchCurrentFileId) {
83+
return [
84+
{
85+
name: "PowerShell: Launch Current File",
86+
type: "PowerShell",
87+
request: "launch",
88+
script: "${file}",
89+
cwd: "${file}",
90+
},
91+
];
92+
}
93+
94+
if (launchSelection.id === launchScriptId) {
95+
return [
96+
{
97+
name: "PowerShell: Launch Script",
98+
type: "PowerShell",
99+
request: "launch",
100+
script: "enter path or command to execute e.g.: ${workspaceFolder}/src/foo.ps1 or Invoke-Pester",
101+
cwd: "${workspaceFolder}",
102+
},
103+
];
104+
}
105+
106+
if (launchSelection.id === interactiveSessionId) {
107+
return [
108+
{
109+
name: "PowerShell: Interactive Session",
110+
type: "PowerShell",
111+
request: "launch",
112+
cwd: "",
113+
},
114+
];
115+
}
116+
117+
// Last remaining possibility is attach to host process
118+
return [
119+
{
120+
name: "PowerShell: Attach to PowerShell Host Process",
121+
type: "PowerShell",
122+
request: "attach",
123+
runspaceId: 1,
124+
},
125+
];
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)