From 13521776303a36d339229fdefab4c6bd418a4e1c Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sat, 13 Jul 2019 18:44:32 -0600 Subject: [PATCH 1/4] WIP: first pass at #1611 - provide dynamic debug config --- package.json | 73 ++++------------------------- src/features/DebugSession.ts | 91 ++++++++++++++++++++++++++++++++++-- 2 files changed, 95 insertions(+), 69 deletions(-) diff --git a/package.json b/package.json index a9f1f4b7b2..a79c27b580 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": { @@ -339,19 +340,6 @@ "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", @@ -430,7 +418,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 +468,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..87e0107a95 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -2,9 +2,10 @@ * Copyright (C) Microsoft Corporation. All rights reserved. *--------------------------------------------------------*/ +import path = require("path"); 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 +43,88 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider })); } + public async provideDebugConfigurations( + folder: WorkspaceFolder | undefined, + token?: CancellationToken): Promise { + + const launchAttachItems = [ + { label: "Launch", + description: "Launch the debugger with a specified script or for the interactive session" }, + { label: "Attach", + description: "Attach the debugger to a running PowerShell Host Process" }, + ]; + + const debugTypeSelection = + await vscode.window.showQuickPick( + launchAttachItems, + { placeHolder: "Would you like to launch or attach the PowerShell debugger?" }); + + let debugConfiguration = []; + + if (debugTypeSelection.label === "Launch") { + const launchCurrentFileLabel = "Launch Current File"; + const launchScriptLabel = "Launch Script"; + const interactiveSessionLabel = "Interactive Session"; + + const launchItems = [ + { label: launchCurrentFileLabel, + description: "Debugs whichever script is in the active editor window" }, + { label: launchScriptLabel, + description: "Debugs the specified script" }, + { label: interactiveSessionLabel, + description: "Debugs scripts or modules executed from the Integrated Console" }, + ]; + + const launchSelection = + await vscode.window.showQuickPick( + launchItems, + { placeHolder: "Select a launch option" }); + + if (launchSelection.label === launchCurrentFileLabel) { + debugConfiguration = [ + { + name: "PowerShell: Launch Current File", + type: "PowerShell", + request: "launch", + script: "${file}", + cwd: "${file}", + }, + ]; + } else if (launchSelection.label === launchScriptLabel) { + debugConfiguration = [ + { + name: "PowerShell: Launch Script", + type: "PowerShell", + request: "launch", + script: "enter path or script to execute e.g.: ${workspaceFolder}/src/foo.ps1 or Invoke-Pester", + cwd: "${workspaceFolder}", + }, + ]; + } else { + debugConfiguration = [ + { + name: "PowerShell: Interactive Session", + type: "PowerShell", + request: "launch", + cwd: "", + }, + ]; + } + } else { + // Return the "Attach to PowerShell Host Process" debug configuration + debugConfiguration = [ + { + name: "PowerShell: Attach to PowerShell Host Process", + type: "PowerShell", + request: "attach", + runspaceId: 1, + }, + ]; + } + + return debugConfiguration; + } + // 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; } From e2aeecdb78bcc378af308f8159bd62b9ff6915b9 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sat, 20 Jul 2019 17:09:47 -0600 Subject: [PATCH 2/4] 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 todebug Pester tests. --- package.json | 36 ++++------ src/features/DebugSession.ts | 124 ++++++++++++++++------------------- 2 files changed, 69 insertions(+), 91 deletions(-) diff --git a/package.json b/package.json index a79c27b580..36c820e81e 100644 --- a/package.json +++ b/package.json @@ -330,19 +330,18 @@ "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 w/Args Prompt", - "description": "Launch current file (in active editor window) under debugger, prompting first for script arguments", + "description": "Launch and debug the file in the currently active editor window, prompting first for arguments", "body": { "name": "PowerShell Launch Current File w/Args Prompt", "type": "PowerShell", @@ -356,31 +355,28 @@ }, { "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", @@ -388,16 +384,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", @@ -418,7 +404,7 @@ }, "args": { "type": "array", - "description": "Command line arguments to pass to the PowerShell script. Specify ${command:SpecifyScriptArgs} if you want to be prompted for the args.", + "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" }, diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 87e0107a95..d409b0c23a 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -47,82 +47,74 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider folder: WorkspaceFolder | undefined, token?: CancellationToken): Promise { - const launchAttachItems = [ - { label: "Launch", - description: "Launch the debugger with a specified script or for the interactive session" }, - { label: "Attach", - description: "Attach the debugger to a running PowerShell Host Process" }, + const launchCurrentFileLabel = "Launch Current File"; + const launchScriptLabel = "Launch Script"; + const interactiveSessionLabel = "Interactive Session"; + + const debugConfigPickItems = [ + { + label: launchCurrentFileLabel, + description: "Launch and debug the file in the currently active editor window", + }, + { + label: launchScriptLabel, + description: "Launch and debug the specified file or command", + }, + { + label: interactiveSessionLabel, + description: "Debug commands executed from the Integrated Console", + }, + { + label: "Attach", + description: "Attach the debugger to a running PowerShell Host Process", + }, ]; - const debugTypeSelection = + const launchSelection = await vscode.window.showQuickPick( - launchAttachItems, - { placeHolder: "Would you like to launch or attach the PowerShell debugger?" }); - - let debugConfiguration = []; - - if (debugTypeSelection.label === "Launch") { - const launchCurrentFileLabel = "Launch Current File"; - const launchScriptLabel = "Launch Script"; - const interactiveSessionLabel = "Interactive Session"; - - const launchItems = [ - { label: launchCurrentFileLabel, - description: "Debugs whichever script is in the active editor window" }, - { label: launchScriptLabel, - description: "Debugs the specified script" }, - { label: interactiveSessionLabel, - description: "Debugs scripts or modules executed from the Integrated Console" }, - ]; + debugConfigPickItems, + { placeHolder: "Select a PowerShell debug configuration" }); - const launchSelection = - await vscode.window.showQuickPick( - launchItems, - { placeHolder: "Select a launch option" }); - - if (launchSelection.label === launchCurrentFileLabel) { - debugConfiguration = [ - { - name: "PowerShell: Launch Current File", - type: "PowerShell", - request: "launch", - script: "${file}", - cwd: "${file}", - }, - ]; - } else if (launchSelection.label === launchScriptLabel) { - debugConfiguration = [ - { - name: "PowerShell: Launch Script", - type: "PowerShell", - request: "launch", - script: "enter path or script to execute e.g.: ${workspaceFolder}/src/foo.ps1 or Invoke-Pester", - cwd: "${workspaceFolder}", - }, - ]; - } else { - debugConfiguration = [ - { - name: "PowerShell: Interactive Session", - type: "PowerShell", - request: "launch", - cwd: "", - }, - ]; - } - } else { - // Return the "Attach to PowerShell Host Process" debug configuration - debugConfiguration = [ + if (launchSelection.label === launchCurrentFileLabel) { + return [ + { + name: "PowerShell: Launch Current File", + type: "PowerShell", + request: "launch", + script: "${file}", + cwd: "${file}", + }, + ]; + } else if (launchSelection.label === launchScriptLabel) { + 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}", + }, + ]; + } else if (launchSelection.label === interactiveSessionLabel) { + return [ { - name: "PowerShell: Attach to PowerShell Host Process", + name: "PowerShell: Interactive Session", type: "PowerShell", - request: "attach", - runspaceId: 1, + request: "launch", + cwd: "", }, ]; } - return debugConfiguration; + // Return the "Attach to PowerShell Host Process" debug configuration + return [ + { + name: "PowerShell: Attach to PowerShell Host Process", + type: "PowerShell", + request: "attach", + runspaceId: 1, + }, + ]; } // DebugConfigurationProvider method From 0f39d44080f470f46d325a017ba4fc5fd1a578e9 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sun, 21 Jul 2019 18:18:45 -0600 Subject: [PATCH 3/4] Remove w/Args prompt debug config snippet Switch to int id check in provideDebugConfig --- package.json | 14 -------------- src/features/DebugSession.ts | 23 ++++++++++++++--------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 36c820e81e..6088fe8366 100644 --- a/package.json +++ b/package.json @@ -339,20 +339,6 @@ "cwd": "^\"\\${file}\"" } }, - { - "label": "PowerShell: Launch Current File w/Args Prompt", - "description": "Launch and debug the file in the currently active editor window, prompting first for 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 and debug the specified file or command", diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index d409b0c23a..a351edd35d 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -47,24 +47,29 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider folder: WorkspaceFolder | undefined, token?: CancellationToken): Promise { - const launchCurrentFileLabel = "Launch Current File"; - const launchScriptLabel = "Launch Script"; - const interactiveSessionLabel = "Interactive Session"; + const launchCurrentFileId = 0; + const launchScriptId = 1; + const interactiveSessionId = 2; + const attachHostProcessId = 3; const debugConfigPickItems = [ { - label: launchCurrentFileLabel, + id: launchCurrentFileId, + label: "Launch Current File", description: "Launch and debug the file in the currently active editor window", }, { - label: launchScriptLabel, + id: launchScriptId, + label: "Launch Script", description: "Launch and debug the specified file or command", }, { - label: interactiveSessionLabel, + 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", }, @@ -75,7 +80,7 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider debugConfigPickItems, { placeHolder: "Select a PowerShell debug configuration" }); - if (launchSelection.label === launchCurrentFileLabel) { + if (launchSelection.id === launchCurrentFileId) { return [ { name: "PowerShell: Launch Current File", @@ -85,7 +90,7 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider cwd: "${file}", }, ]; - } else if (launchSelection.label === launchScriptLabel) { + } else if (launchSelection.id === launchScriptId) { return [ { name: "PowerShell: Launch Script", @@ -95,7 +100,7 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider cwd: "${workspaceFolder}", }, ]; - } else if (launchSelection.label === interactiveSessionLabel) { + } else if (launchSelection.id === interactiveSessionId) { return [ { name: "PowerShell: Interactive Session", From a8b7be57d654eb61d59fb95757870fb9d6622631 Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sun, 28 Jul 2019 10:25:32 -0600 Subject: [PATCH 4/4] Address PR feedback, remove path as it wasn't being used --- src/features/DebugSession.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index a351edd35d..4c092f2f6e 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -2,7 +2,6 @@ * Copyright (C) Microsoft Corporation. All rights reserved. *--------------------------------------------------------*/ -import path = require("path"); import vscode = require("vscode"); import { CancellationToken, DebugConfiguration, DebugConfigurationProvider, ExtensionContext, WorkspaceFolder } from "vscode"; @@ -90,7 +89,9 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider cwd: "${file}", }, ]; - } else if (launchSelection.id === launchScriptId) { + } + + if (launchSelection.id === launchScriptId) { return [ { name: "PowerShell: Launch Script", @@ -100,7 +101,9 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider cwd: "${workspaceFolder}", }, ]; - } else if (launchSelection.id === interactiveSessionId) { + } + + if (launchSelection.id === interactiveSessionId) { return [ { name: "PowerShell: Interactive Session", @@ -111,7 +114,7 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider ]; } - // Return the "Attach to PowerShell Host Process" debug configuration + // Last remaining possibility is attach to host process return [ { name: "PowerShell: Attach to PowerShell Host Process",