Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
73 changes: 8 additions & 65 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 @@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down Expand Up @@ -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": {
Expand Down
91 changes: 87 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,88 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider
}));
}

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

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,
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