diff --git a/src/PowerShellEditorServices.Protocol/DebugAdapter/LaunchRequest.cs b/src/PowerShellEditorServices.Protocol/DebugAdapter/LaunchRequest.cs
index 86437b16c..1bf5c9ea1 100644
--- a/src/PowerShellEditorServices.Protocol/DebugAdapter/LaunchRequest.cs
+++ b/src/PowerShellEditorServices.Protocol/DebugAdapter/LaunchRequest.cs
@@ -18,12 +18,6 @@ public static readonly
public class LaunchRequestArguments
{
- ///
- /// Gets or sets the absolute path to the program to debug.
- ///
- [Obsolete("This property has been deprecated in favor of the Script property.")]
- public string Program { get; set; }
-
///
/// Gets or sets the absolute path to the script to debug.
///
diff --git a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs
index fd3436784..e867e79e8 100644
--- a/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs
+++ b/src/PowerShellEditorServices.Protocol/Server/DebugAdapter.cs
@@ -254,55 +254,56 @@ protected async Task HandleLaunchRequest(
{
this.RegisterEventHandlers();
- // Set the working directory for the PowerShell runspace to the cwd passed in via launch.json.
- // In case that is null, use the the folder of the script to be executed. If the resulting
- // working dir path is a file path then extract the directory and use that.
- string workingDir =
- launchParams.Cwd ??
- launchParams.Script ??
-#pragma warning disable 618
- launchParams.Program;
-#pragma warning restore 618
-
- // When debugging an "untitled" (unsaved) file - the working dir can't be derived
- // from the Script path. OTOH, if the launch params specifies a Cwd, use it.
- if (ScriptFile.IsUntitledPath(workingDir) && string.IsNullOrEmpty(launchParams.Cwd))
+ // Determine whether or not the working directory should be set in the PowerShellContext.
+ if ((this.editorSession.PowerShellContext.CurrentRunspace.Location == RunspaceLocation.Local) &&
+ !this.editorSession.DebugService.IsDebuggerStopped)
{
- workingDir = null;
- }
+ // Get the working directory that was passed via the debug config
+ // (either via launch.json or generated via no-config debug).
+ string workingDir = launchParams.Cwd;
- if (!string.IsNullOrEmpty(workingDir))
- {
- workingDir = PowerShellContext.UnescapePath(workingDir);
- try
+ // Assuming we have a non-empty/null working dir, unescape the path and verify
+ // the path exists and is a directory.
+ if (!string.IsNullOrEmpty(workingDir))
{
- if ((File.GetAttributes(workingDir) & FileAttributes.Directory) != FileAttributes.Directory)
+ workingDir = PowerShellContext.UnescapePath(workingDir);
+ try
{
- workingDir = Path.GetDirectoryName(workingDir);
+ if ((File.GetAttributes(workingDir) & FileAttributes.Directory) != FileAttributes.Directory)
+ {
+ workingDir = Path.GetDirectoryName(workingDir);
+ }
+ }
+ catch (Exception ex)
+ {
+ workingDir = null;
+ Logger.Write(
+ LogLevel.Error,
+ $"The specified 'cwd' path is invalid: '{launchParams.Cwd}'. Error: {ex.Message}");
}
}
- catch (Exception ex)
- {
- Logger.Write(LogLevel.Error, "cwd path is invalid: " + ex.Message);
-
- workingDir = null;
- }
- }
- if (string.IsNullOrEmpty(workingDir))
- {
+ // If we have no working dir by this point and we are running in a temp console,
+ // pick some reasonable default.
+ if (string.IsNullOrEmpty(workingDir) && launchParams.CreateTemporaryIntegratedConsole)
+ {
#if CoreCLR
- workingDir = AppContext.BaseDirectory;
+ //TODO: RKH 2018-06-26 .NET standard 2.0 has added Environment.CurrentDirectory - let's use it.
+ workingDir = AppContext.BaseDirectory;
#else
- workingDir = Environment.CurrentDirectory;
+ workingDir = Environment.CurrentDirectory;
#endif
- }
+ }
- if (this.editorSession.PowerShellContext.CurrentRunspace.Location == RunspaceLocation.Local &&
- !this.editorSession.DebugService.IsDebuggerStopped)
- {
- await editorSession.PowerShellContext.SetWorkingDirectory(workingDir, isPathAlreadyEscaped: false);
- Logger.Write(LogLevel.Verbose, "Working dir set to: " + workingDir);
+ // At this point, we will either have a working dir that should be set to cwd in
+ // the PowerShellContext or the user has requested (via an empty/null cwd) that
+ // the working dir should not be changed.
+ if (!string.IsNullOrEmpty(workingDir))
+ {
+ await editorSession.PowerShellContext.SetWorkingDirectory(workingDir, isPathAlreadyEscaped: false);
+ }
+
+ Logger.Write(LogLevel.Verbose, $"Working dir " + (string.IsNullOrEmpty(workingDir) ? "not set." : $"set to '{workingDir}'"));
}
// Prepare arguments to the script - if specified
@@ -315,9 +316,7 @@ protected async Task HandleLaunchRequest(
// Store the launch parameters so that they can be used later
this.noDebug = launchParams.NoDebug;
-#pragma warning disable 618
- this.scriptToLaunch = launchParams.Script ?? launchParams.Program;
-#pragma warning restore 618
+ this.scriptToLaunch = launchParams.Script;
this.arguments = arguments;
this.IsUsingTempIntegratedConsole = launchParams.CreateTemporaryIntegratedConsole;