Skip to content

Fix issue with dbg launch of script 'Invoke-Pester'. #658

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 1 commit into from
Apr 7, 2017
Merged
Changes from all 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
35 changes: 21 additions & 14 deletions src/features/DebugSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ export class DebugSessionFeature implements IFeature {
private startDebugSession(config: any) {

let currentDocument = vscode.window.activeTextEditor.document;
let debugCurrentScript = (config.script === "${file}") || !config.request;
let generateLaunchConfig = !config.request;

if (!config.request) {
// No launch.json, create the default configuration
if (generateLaunchConfig) {
// No launch.json, create the default configuration for both unsaved (Untitled) and saved documents.
config.type = 'PowerShell';
config.name = 'PowerShell Launch Current File';
config.request = 'launch';
Expand All @@ -38,19 +40,30 @@ export class DebugSessionFeature implements IFeature {
currentDocument.isUntitled
? currentDocument.uri.toString()
: currentDocument.fileName;

// For a folder-less workspace, vscode.workspace.rootPath will be undefined.
// PSES will convert that undefined to a reasonable working dir.
config.cwd =
currentDocument.isUntitled
? vscode.workspace.rootPath
: currentDocument.fileName;
}

if (config.request === 'launch') {
// Make sure there's a usable working directory if possible
config.cwd = config.cwd || vscode.workspace.rootPath;

// For launch of "current script", don't start the debugger if the current file
// is not a file that can be debugged by PowerShell
if (config.script === "${file}") {
// For debug launch of "current script" (saved or unsaved), warn before starting the debugger if either
// A) the unsaved document's language type is not PowerShell or
// B) the saved document's extension is a type that PowerShell can't debug.
if (debugCurrentScript) {

if (currentDocument.isUntitled) {
if (currentDocument.languageId === 'powershell') {
config.script = currentDocument.uri.toString();
if (!generateLaunchConfig) {
// Cover the case of existing launch.json but unsaved (Untitled) document.
// In this case, vscode.workspace.rootPath will not be undefined.
config.script = currentDocument.uri.toString();
config.cwd = vscode.workspace.rootPath
}
}
else {
let msg = "To debug '" + currentDocument.fileName +
Expand Down Expand Up @@ -80,12 +93,6 @@ export class DebugSessionFeature implements IFeature {
}
}
}
else if (config.script) {
// In this case, the user has explicitly defined a script path
// so make sure to set the cwd to that path if the cwd wasn't
// explicitly set
config.cwd = config.cwd || config.script;
}
}

// Prevent the Debug Console from opening
Expand Down