Skip to content

Implement #1611 - provide dynamic debug config #2084

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 18 additions & 89 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 @@ -66,6 +67,11 @@
"test": "node ./node_modules/vscode/bin/test"
},
"contributes": {
"breakpoints": [
{
"language": "powershell"
}
],
"viewsContainers": {
"activitybar": [
{
Expand Down Expand Up @@ -311,11 +317,6 @@
{
"type": "PowerShell",
"label": "PowerShell",
"enableBreakpointsFor": {
"languageIds": [
"powershell"
]
},
"program": "./out/src/debugAdapter.js",
"runtime": "node",
"variables": {
Expand All @@ -329,32 +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 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",
"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",
Expand All @@ -368,48 +355,35 @@
},
{
"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 @@ -430,7 +404,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 @@ -480,52 +454,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
83 changes: 79 additions & 4 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -42,6 +43,80 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
}));
}

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

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 launchSelection =
await vscode.window.showQuickPick(
debugConfigPickItems,
{ placeHolder: "Select a PowerShell debug configuration" });

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: Interactive Session",
type: "PowerShell",
request: "launch",
cwd: "",
},
];
}

// 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
public async resolveDebugConfiguration(
folder: WorkspaceFolder | undefined,
Expand Down Expand Up @@ -161,13 +236,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