diff --git a/package.json b/package.json index a9f1f4b7b2..6088fe8366 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ }, "main": "./out/src/main", "activationEvents": [ + "onDebugInitialConfigurations", "onDebugResolve:powershell", "onLanguage:powershell", "onCommand:PowerShell.NewProjectFromTemplate", @@ -66,6 +67,11 @@ "test": "node ./node_modules/vscode/bin/test" }, "contributes": { + "breakpoints": [ + { + "language": "powershell" + } + ], "viewsContainers": { "activitybar": [ { @@ -311,11 +317,6 @@ { "type": "PowerShell", "label": "PowerShell", - "enableBreakpointsFor": { - "languageIds": [ - "powershell" - ] - }, "program": "./out/src/debugAdapter.js", "runtime": "node", "variables": { @@ -329,70 +330,39 @@ "configurationSnippets": [ { "label": "PowerShell: Launch Current File", - "description": "Launch current file (in active editor window) under debugger", + "description": "Launch and debug the file in the currently active editor window", "body": { "name": "PowerShell Launch Current File", "type": "PowerShell", "request": "launch", "script": "^\"\\${file}\"", - "args": [], - "cwd": "^\"\\${file}\"" - } - }, - { - "label": "PowerShell: Launch Current File in Temporary Console", - "description": "Launch current file (in active editor window) under debugger in a temporary Integrated Console.", - "body": { - "name": "PowerShell Launch Current File in Temporary Console", - "type": "PowerShell", - "request": "launch", - "script": "^\"\\${file}\"", - "args": [], - "cwd": "^\"\\${file}\"", - "createTemporaryIntegratedConsole": true - } - }, - { - "label": "PowerShell: Launch Current File w/Args Prompt", - "description": "Launch current file (in active editor window) under debugger, prompting first for script arguments", - "body": { - "name": "PowerShell Launch Current File w/Args Prompt", - "type": "PowerShell", - "request": "launch", - "script": "^\"\\${file}\"", - "args": [ - "^\"\\${command:SpecifyScriptArgs}\"" - ], "cwd": "^\"\\${file}\"" } }, { "label": "PowerShell: Launch Script", - "description": "Launch specified script or path to script under debugger", + "description": "Launch and debug the specified file or command", "body": { - "name": "PowerShell Launch ${Script}", + "name": "PowerShell Launch Script", "type": "PowerShell", "request": "launch", - "script": "^\"\\${workspaceFolder}/${Script}\"", - "args": [], + "script": "^\"enter path or command to execute e.g.: \\${workspaceFolder}/src/foo.ps1 or Invoke-Pester\"", "cwd": "^\"\\${workspaceFolder}\"" } }, { - "label": "PowerShell: Pester Tests", - "description": "Invokes Pester tests under debugger", + "label": "PowerShell: Interactive Session", + "description": "Debug commands executed from the Integrated Console", "body": { - "name": "PowerShell Pester Tests", + "name": "PowerShell Interactive Session", "type": "PowerShell", "request": "launch", - "script": "Invoke-Pester", - "args": [], - "cwd": "^\"\\${workspaceFolder}\"" + "cwd": "" } }, { "label": "PowerShell: Attach to PowerShell Host Process", - "description": "Open host process picker to select process to attach debugger to", + "description": "Attach the debugger to a running PowerShell Host Process", "body": { "name": "PowerShell Attach to Host Process", "type": "PowerShell", @@ -400,16 +370,6 @@ "runspaceId": 1 } }, - { - "label": "PowerShell: Interactive Session", - "description": "Start interactive session (Debug Console) under debugger", - "body": { - "name": "PowerShell Interactive Session", - "type": "PowerShell", - "request": "launch", - "cwd": "" - } - }, { "label": "PowerShell: Attach Interactive Session Runspace", "description": "Open runspace picker to select runspace to attach debugger to", @@ -430,7 +390,7 @@ }, "args": { "type": "array", - "description": "Command line arguments to pass to the PowerShell script.", + "description": "Command line arguments to pass to the PowerShell script. Specify \"${command:SpecifyScriptArgs}\" if you want to be prompted for the args.", "items": { "type": "string" }, @@ -480,52 +440,7 @@ } } }, - "initialConfigurations": [ - { - "name": "PowerShell Launch Current File", - "type": "PowerShell", - "request": "launch", - "script": "${file}", - "args": [], - "cwd": "${file}" - }, - { - "name": "PowerShell Launch Current File in Temporary Console", - "type": "PowerShell", - "request": "launch", - "script": "${file}", - "args": [], - "cwd": "${file}", - "createTemporaryIntegratedConsole": true - }, - { - "name": "PowerShell Launch Current File w/Args Prompt", - "type": "PowerShell", - "request": "launch", - "script": "${file}", - "args": [ - "${command:SpecifyScriptArgs}" - ], - "cwd": "${file}" - }, - { - "name": "PowerShell Attach to Host Process", - "type": "PowerShell", - "request": "attach" - }, - { - "name": "PowerShell Interactive Session", - "type": "PowerShell", - "request": "launch", - "cwd": "" - }, - { - "name": "PowerShell Attach Interactive Session Runspace", - "type": "PowerShell", - "request": "attach", - "processId": "current" - } - ] + "initialConfigurations": [] } ], "configuration": { diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 64826ca90e..4c092f2f6e 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -4,7 +4,7 @@ import vscode = require("vscode"); import { CancellationToken, DebugConfiguration, DebugConfigurationProvider, - ExtensionContext, ProviderResult, WorkspaceFolder } from "vscode"; + ExtensionContext, WorkspaceFolder } from "vscode"; import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient"; import { IFeature } from "../feature"; import { getPlatformDetails, OperatingSystem } from "../platform"; @@ -42,6 +42,89 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider })); } + public async provideDebugConfigurations( + folder: WorkspaceFolder | undefined, + token?: CancellationToken): Promise { + + const launchCurrentFileId = 0; + const launchScriptId = 1; + const interactiveSessionId = 2; + const attachHostProcessId = 3; + + const debugConfigPickItems = [ + { + id: launchCurrentFileId, + label: "Launch Current File", + description: "Launch and debug the file in the currently active editor window", + }, + { + id: launchScriptId, + label: "Launch Script", + description: "Launch and debug the specified file or command", + }, + { + id: interactiveSessionId, + label: "Interactive Session", + description: "Debug commands executed from the Integrated Console", + }, + { + id: attachHostProcessId, + label: "Attach", + description: "Attach the debugger to a running PowerShell Host Process", + }, + ]; + + const launchSelection = + await vscode.window.showQuickPick( + debugConfigPickItems, + { placeHolder: "Select a PowerShell debug configuration" }); + + if (launchSelection.id === launchCurrentFileId) { + return [ + { + name: "PowerShell: Launch Current File", + type: "PowerShell", + request: "launch", + script: "${file}", + cwd: "${file}", + }, + ]; + } + + if (launchSelection.id === launchScriptId) { + return [ + { + name: "PowerShell: Launch Script", + type: "PowerShell", + request: "launch", + script: "enter path or command to execute e.g.: ${workspaceFolder}/src/foo.ps1 or Invoke-Pester", + cwd: "${workspaceFolder}", + }, + ]; + } + + if (launchSelection.id === interactiveSessionId) { + return [ + { + name: "PowerShell: Interactive Session", + type: "PowerShell", + request: "launch", + cwd: "", + }, + ]; + } + + // Last remaining possibility is attach to host process + return [ + { + name: "PowerShell: Attach to PowerShell Host Process", + type: "PowerShell", + request: "attach", + runspaceId: 1, + }, + ]; + } + // DebugConfigurationProvider method public async resolveDebugConfiguration( folder: WorkspaceFolder | undefined, @@ -161,13 +244,13 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider } if ((currentDocument.languageId !== "powershell") || !isValidExtension) { - let path = currentDocument.fileName; + let docPath = currentDocument.fileName; const workspaceRootPath = vscode.workspace.rootPath; if (currentDocument.fileName.startsWith(workspaceRootPath)) { - path = currentDocument.fileName.substring(vscode.workspace.rootPath.length + 1); + docPath = currentDocument.fileName.substring(vscode.workspace.rootPath.length + 1); } - const msg = "PowerShell does not support debugging this file type: '" + path + "'."; + const msg = "PowerShell does not support debugging this file type: '" + docPath + "'."; vscode.window.showErrorMessage(msg); return; }