Skip to content

Commit

Permalink
Implement PowerShell#1611 - provide dynamic debug config (PowerShell#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
rkeithhill authored and TylerLeonhardt committed Sep 20, 2019
1 parent 75d3138 commit 851ed5e
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 106 deletions.
119 changes: 17 additions & 102 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
},
"main": "./out/src/main",
"activationEvents": [
"onDebugInitialConfigurations",
"onDebugResolve:powershell",
"onLanguage:powershell",
"onCommand:PowerShell.NewProjectFromTemplate",
Expand Down Expand Up @@ -70,6 +71,11 @@
"test": "node ./node_modules/vscode/bin/test"
},
"contributes": {
"breakpoints": [
{
"language": "powershell"
}
],
"viewsContainers": {
"activitybar": [
{
Expand Down Expand Up @@ -315,11 +321,6 @@
{
"type": "PowerShell",
"label": "PowerShell",
"enableBreakpointsFor": {
"languageIds": [
"powershell"
]
},
"program": "./out/src/debugAdapter.js",
"runtime": "node",
"variables": {
Expand All @@ -333,87 +334,46 @@
"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",
"request": "attach",
"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",
Expand All @@ -434,7 +394,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"
},
Expand Down Expand Up @@ -484,52 +444,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": {
Expand Down
91 changes: 87 additions & 4 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -42,6 +42,89 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
}));
}

public async provideDebugConfigurations(
folder: WorkspaceFolder | undefined,
token?: CancellationToken): Promise<DebugConfiguration[]> {

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,
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 851ed5e

Please sign in to comment.