From 7f7e733dd3435df91e38d663a10515ef6e0ae30d Mon Sep 17 00:00:00 2001 From: xWTF Date: Sat, 28 Jan 2023 20:41:23 +0800 Subject: [PATCH 1/3] Use PathString in record, for OrdinalIgnoreCase compare --- PathString.cs | 37 +++++++++++++++++++++++++++++ WorkspacesHelper/VSCodeWorkspace.cs | 7 +++--- 2 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 PathString.cs 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 }; - } } From 167773ffdb2fd085cb7c9179f598517d6a15a8fd Mon Sep 17 00:00:00 2001 From: xWTF Date: Sat, 28 Jan 2023 20:41:39 +0800 Subject: [PATCH 2/3] Pass unescaped URI when parsing workspace --- WorkspacesHelper/VSCodeWorkspacesApi.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From 77cd93c1d3512c7b2ef38434dae17bc4fe4b19cb Mon Sep 17 00:00:00 2001 From: xWTF Date: Wed, 22 Mar 2023 16:56:25 +0800 Subject: [PATCH 3/3] Bump version to 1.2.2 --- plugin.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 +}