-
Notifications
You must be signed in to change notification settings - Fork 238
Change debug launch handler to treat null/empty cwd to not change dir #694
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -255,22 +255,9 @@ 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)) | ||
{ | ||
workingDir = null; | ||
} | ||
string workingDir = launchParams.Cwd; | ||
|
||
// Assuming we have a specified working dir, unescape the path and verify it. | ||
if (!string.IsNullOrEmpty(workingDir)) | ||
{ | ||
workingDir = PowerShellContext.UnescapePath(workingDir); | ||
|
@@ -289,18 +276,28 @@ protected async Task HandleLaunchRequest( | |
} | ||
} | ||
|
||
if (string.IsNullOrEmpty(workingDir)) | ||
// A null or empty string value for CWD is an indicator to NOT change the working directory | ||
// but only if we are debugging in the integrated console where there is an existing cwd. | ||
// However, if we are running in a temporary integrated console, there is no pre-existing | ||
// cwd, so fall through to the "else if: where we set a working directory. | ||
if (string.IsNullOrEmpty(workingDir) && !launchParams.CreateTemporaryIntegratedConsole) | ||
{ | ||
Logger.Write(LogLevel.Verbose, "Launch config requested working dir not be changed/set"); | ||
} | ||
else if (this.editorSession.PowerShellContext.CurrentRunspace.Location == RunspaceLocation.Local && | ||
!this.editorSession.DebugService.IsDebuggerStopped) | ||
{ | ||
// If we have no working dir by this point, pick some reasonable default. | ||
if (string.IsNullOrEmpty(workingDir)) | ||
{ | ||
#if CoreCLR | ||
workingDir = AppContext.BaseDirectory; | ||
//TODO: RKH 2018-06-26 .NET standard 2.0 has added Environment.CurrentDirectory - let's use it. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. soon.... :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
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); | ||
} | ||
|
@@ -316,7 +313,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; | ||
this.scriptToLaunch = launchParams.Script; | ||
#pragma warning restore 618 | ||
this.arguments = arguments; | ||
this.IsUsingTempIntegratedConsole = launchParams.CreateTemporaryIntegratedConsole; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't look like this if is doing anything besides logging... maybe refactor to just an if statement and then after the if log the location of the workingDir?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, in the case above we don't know or care about the location of the working dir but we can simplify the logic and put in a single log call. Inside that log call I can use a ternary to determine what to log.