diff --git a/PathString.cs b/PathString.cs new file mode 100644 index 0000000..dcc04b5 --- /dev/null +++ b/PathString.cs @@ -0,0 +1,37 @@ +using System; + +namespace Flow.Plugin.VSCodeWorkspaces +{ + public readonly struct PathString : IEquatable + { + public readonly string Value; + + public PathString(string value) => Value = value; + + // Better debugging experience :) + public override string ToString() => Value; + + // Linq compoares HashCode first + public override int GetHashCode() => StringComparer.OrdinalIgnoreCase.GetHashCode(Value); + + // Then IEquatable.Equals, follow MS best practice + // https://learn.microsoft.com/en-us/dotnet/standard/base-types/best-practices-strings?redirectedfrom=MSDN#:~:text=XML%20and%20HTTP.-,File%20paths.,-Registry%20keys%20and + public bool Equals(PathString other) => string.Equals(Value, other.Value, StringComparison.OrdinalIgnoreCase); + + // Default object.Equals, just in case + public override bool Equals(object other) + { + if (other is PathString ps) + return Equals(ps); + if (other is string s) + return string.Equals(Value, s, StringComparison.OrdinalIgnoreCase); + return base.Equals(other); + } + + public static bool operator ==(PathString left, PathString right) => left.Equals(right); + public static bool operator !=(PathString left, PathString right) => !(left == right); + + public static implicit operator string(PathString h) => h.Value; + public static implicit operator PathString(string s) => new(s); + } +} diff --git a/WorkspacesHelper/VSCodeWorkspace.cs b/WorkspacesHelper/VSCodeWorkspace.cs index 7fd8a7b..45b71fc 100644 --- a/WorkspacesHelper/VSCodeWorkspace.cs +++ b/WorkspacesHelper/VSCodeWorkspace.cs @@ -10,11 +10,11 @@ namespace Flow.Plugin.VSCodeWorkspaces.WorkspacesHelper { public record VSCodeWorkspace { - public string Path { get; init; } + public PathString Path { get; init; } - public string RelativePath { get; init; } + public PathString RelativePath { get; init; } - public string FolderName { get; init; } + public PathString FolderName { get; init; } public string ExtraInfo { get; init; } @@ -34,7 +34,6 @@ public string WorkspaceTypeToString() TypeWorkspace.DevContainer => Resources.TypeWorkspaceDevContainer, _ => string.Empty }; - } } diff --git a/WorkspacesHelper/VSCodeWorkspacesApi.cs b/WorkspacesHelper/VSCodeWorkspacesApi.cs index 480cf2a..ade0399 100644 --- a/WorkspacesHelper/VSCodeWorkspacesApi.cs +++ b/WorkspacesHelper/VSCodeWorkspacesApi.cs @@ -37,7 +37,7 @@ public static VSCodeWorkspace ParseVSCodeUri(string uri, VSCodeInstance vscodeIn return new VSCodeWorkspace() { - Path = uri, + Path = unescapeUri, RelativePath = typeWorkspace.Path, FolderName = folderName, ExtraInfo = typeWorkspace.MachineName, diff --git a/plugin.json b/plugin.json index d4b7130..ad6eba3 100644 --- a/plugin.json +++ b/plugin.json @@ -4,10 +4,10 @@ "ActionKeyword": "{", "Name": "VS Code Workspaces", "Author": "ricardosantos9521", - "Version": "1.2.1", + "Version": "1.2.2", "Language": "csharp", "Website": "https://github.com/ricardosantos9521/PowerToys/", "ExecuteFileName": "Flow.Plugin.VSCodeWorkspaces.dll", "IsGlobal": false, "IcoPath": "Images\\code-light.png" -} \ No newline at end of file +}