Skip to content

Conversation

@rkeithhill
Copy link
Contributor

Fix for PowerShell/vscode-powershell#1330

Removes deprecated "Program" field from LaunchRequest class.
Simplifies working dir logic in HandleLaunchRequest. Basically if the
launch request happens in the regular integrated console, a null/empty
cwd means "do not change the working dir". If the request is using the
temp integrated console, there is no "existing" workng dir, so we use
the original logic to set the working dir.

Fix for PowerShell/vscode-powershell#1330

Removes deprecated "Program" field from LaunchRequest class.
Simplifies working dir logic in HandleLaunchRequest.  Basically if the
launch request happens in the regular integrated console, a null/empty
cwd means "do not change the working dir".  If the request is using the
temp integrated console, there is no "existing" workng dir, so we use
the original logic to set the working dir.
@rkeithhill
Copy link
Contributor Author

BTW please thoroughly review this one. We are changing the way we handle a launch request with a null or empty cwd. In theory, the main impact is the "no debug config" scenario and then any debug config where cwd is not set. The latter is easy to work around - set cwd in your debug config to whatever you want (or set to "" to keep working dir unchanged).

// 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");
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

@TylerLeonhardt TylerLeonhardt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Keith!

try
{
workingDir = Path.GetDirectoryName(workingDir);
if ((File.GetAttributes(workingDir) & FileAttributes.Directory) != FileAttributes.Directory)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is this magical syntax?
File.GetAttributes(workingDir) & FileAttributes.Directory

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enums as flags. Attributes are usually modelled as flag enums by C# to make them more readable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(See here)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I usually see the check as != 0, but another recommendation I've seen is to use HasFlag():

if (File.GetAttributes(workingDir).HasFlag(FileAttributes.Directory))
{
    ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently HasFlag() was added in .NET 4.

if (string.IsNullOrEmpty(workingDir) && launchParams.CreateTemporaryIntegratedConsole)
{
#if CoreCLR
//TODO: RKH 2018-06-26 .NET standard 2.0 has added Environment.CurrentDirectory - let's use it.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soon.... :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// Store the launch parameters so that they can be used later
this.noDebug = launchParams.NoDebug;
#pragma warning disable 618
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the pragma can be removed -- 618 is to suppress "Obselete"

@rkeithhill rkeithhill merged commit 4d4d729 into master Jul 4, 2018
@rkeithhill rkeithhill deleted the rkeithhill/change-cwd-handling-launch-request branch July 4, 2018 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants