From 2adebf8867f03ad25a77078d0589f56149dd0b0e Mon Sep 17 00:00:00 2001 From: Keith Hill Date: Sun, 1 Jul 2018 18:35:53 -0600 Subject: [PATCH] Allow debugging in interactive session with no dir change Fix #1330 This PR depends on a corresponding PR to PSES to have it handle null/empty string differently in the non-temp console case. For the generateLaunchConfig case, we now pass "" as cwd to PSES. That tells PSES to not change the directory *if* we aren't running in a temp console. If we are in a temp console, then use old logic to set working dir. Update "PowerShell Interactive Session" debug config to tell PSES to not change the working dir. Remove "program" field from launch config. This has been marked deprecated for over a year now. Change refs in ${workspaceRoot} to ${workpaceFolder} to work better in a multi-workspace environment. Remove unused imports/field in DebugSession.ts. --- package.json | 18 +++++++----------- src/features/DebugSession.ts | 25 ++++++++++++++----------- 2 files changed, 21 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 9fe3717750..8c28288f1e 100644 --- a/package.json +++ b/package.json @@ -257,9 +257,9 @@ "type": "PowerShell", "request": "launch", "name": "PowerShell Launch ${Script}", - "script": "^\"\\${workspaceRoot}/${Script}\"", + "script": "^\"\\${workspaceFolder}/${Script}\"", "args": [], - "cwd": "^\"\\${workspaceRoot}\"" + "cwd": "^\"\\${workspaceFolder}\"" } }, { @@ -271,7 +271,7 @@ "name": "PowerShell Pester Tests", "script": "Invoke-Pester", "args": [], - "cwd": "^\"\\${workspaceRoot}\"" + "cwd": "^\"\\${workspaceFolder}\"" } }, { @@ -292,17 +292,13 @@ "type": "PowerShell", "request": "launch", "name": "PowerShell Interactive Session", - "cwd": "^\"\\${workspaceRoot}\"" + "cwd": "" } } ], "configurationAttributes": { "launch": { "properties": { - "program": { - "type": "string", - "description": "Deprecated. Please use the 'script' property instead to specify the absolute path to the PowerShell script to launch under the debugger." - }, "script": { "type": "string", "description": "Optional: Absolute path to the PowerShell script to launch under the debugger." @@ -317,8 +313,8 @@ }, "cwd": { "type": "string", - "description": "Absolute path to the working directory. Default is the current workspace.", - "default": "${workspaceRoot}" + "description": "Absolute path to the working directory. Default is the current workspace folder.", + "default": "${workspaceFolder}" }, "createTemporaryIntegratedConsole": { "type": "boolean", @@ -385,7 +381,7 @@ "type": "PowerShell", "request": "launch", "name": "PowerShell Interactive Session", - "cwd": "${workspaceRoot}" + "cwd": "" } ] } diff --git a/src/features/DebugSession.ts b/src/features/DebugSession.ts index 902d314a07..e488f464b9 100644 --- a/src/features/DebugSession.ts +++ b/src/features/DebugSession.ts @@ -2,14 +2,12 @@ * Copyright (C) Microsoft Corporation. All rights reserved. *--------------------------------------------------------*/ -import { hostname } from "os"; -import { dirname } from "path"; import vscode = require("vscode"); import { CancellationToken, DebugConfiguration, DebugConfigurationProvider, ExtensionContext, ProviderResult, WorkspaceFolder } from "vscode"; -import { LanguageClient, NotificationType, RequestType } from "vscode-languageclient"; +import { LanguageClient, RequestType } from "vscode-languageclient"; import { IFeature } from "../feature"; -import { getPlatformDetails, IPlatformDetails, OperatingSystem } from "../platform"; +import { getPlatformDetails, OperatingSystem } from "../platform"; import { PowerShellProcess} from "../process"; import { SessionManager } from "../session"; import Settings = require("../settings"); @@ -19,7 +17,6 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider private sessionCount: number = 1; private command: vscode.Disposable; - private examplesPath: string; private tempDebugProcess: PowerShellProcess; constructor(context: ExtensionContext, private sessionManager: SessionManager) { @@ -75,12 +72,18 @@ export class DebugSessionFeature implements IFeature, DebugConfigurationProvider ? 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 (settings.debugging.createTemporaryIntegratedConsole) { + // 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; + + } else { + // If the non-temp integrated console is being used, default to the current working dir. + config.cwd = ""; + } } if (config.request === "launch") {