-
Notifications
You must be signed in to change notification settings - Fork 234
Add artificial stack frame to represent contexts without one #1898
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 all commits
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT License. | ||
|
||
using System; | ||
using System.IO; | ||
using System.Management.Automation; | ||
using System.Runtime.InteropServices; | ||
|
@@ -29,13 +30,48 @@ internal static class PathUtils | |
/// </summary> | ||
internal static readonly char AlternatePathSeparator = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? '/' : '\\'; | ||
|
||
/// <summary> | ||
/// The <see cref="StringComparison" /> value to be used when comparing paths. Will be | ||
/// <see cref="StringComparison.Ordinal" /> for case sensitive file systems and <see cref="StringComparison.OrdinalIgnoreCase" /> | ||
/// in case insensitive file systems. | ||
/// </summary> | ||
internal static readonly StringComparison PathComparison = RuntimeInformation.IsOSPlatform(OSPlatform.Linux) | ||
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. Platform checks are sort of littered throughout the project. It'd be nice to go through and replace these with centralized logic. (It's optimized by the JIT anyway iirc so it's not a perf boost at least outside of Windows PowerShell, but nice for maintenance) 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. 💯 agree! |
||
? StringComparison.Ordinal | ||
: StringComparison.OrdinalIgnoreCase; | ||
|
||
/// <summary> | ||
/// Converts all alternate path separators to the current platform's main path separators. | ||
/// </summary> | ||
/// <param name="path">The path to normalize.</param> | ||
/// <returns>The normalized path.</returns> | ||
public static string NormalizePathSeparators(string path) => string.IsNullOrWhiteSpace(path) ? path : path.Replace(AlternatePathSeparator, DefaultPathSeparator); | ||
|
||
/// <summary> | ||
/// Determines whether two specified strings represent the same path. | ||
/// </summary> | ||
/// <param name="left">The first path to compare, or <see langword="null" />.</param> | ||
/// <param name="right">The second path to compare, or <see langword="null" />.</param> | ||
/// <returns> | ||
/// <see langword="true" /> if the value of <paramref name="left" /> represents the same | ||
/// path as the value of <paramref name="right" />; otherwise, <see langword="false" />. | ||
/// </returns> | ||
internal static bool IsPathEqual(string left, string right) | ||
{ | ||
if (string.IsNullOrEmpty(left)) | ||
{ | ||
return string.IsNullOrEmpty(right); | ||
} | ||
|
||
if (string.IsNullOrEmpty(right)) | ||
{ | ||
return false; | ||
} | ||
|
||
left = Path.GetFullPath(left).TrimEnd(DefaultPathSeparator); | ||
right = Path.GetFullPath(right).TrimEnd(DefaultPathSeparator); | ||
return left.Equals(right, PathComparison); | ||
} | ||
|
||
/// <summary> | ||
/// Return the given path with all PowerShell globbing characters escaped, | ||
/// plus optionally the whitespace. | ||
|
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.
Normally I'd prefer to push this into the code for
FetchStackFramesAndVariablesAsync
but that would require giving it more context than it typically needs. Since this should be an edge case rather than the norm, I lean towards this being preferable.That said I'm open to switching it up and just passing more context to fetch.