Skip to content

Commit

Permalink
Merge pull request #4 from xWTF/main
Browse files Browse the repository at this point in the history
Fix duplication when using custom workspaces
  • Loading branch information
taooceros authored Mar 22, 2023
2 parents b2eedf3 + 77cd93c commit 5e4e1c5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 7 deletions.
37 changes: 37 additions & 0 deletions PathString.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;

namespace Flow.Plugin.VSCodeWorkspaces
{
public readonly struct PathString : IEquatable<PathString>
{
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);
}
}
7 changes: 3 additions & 4 deletions WorkspacesHelper/VSCodeWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -34,7 +34,6 @@ public string WorkspaceTypeToString()
TypeWorkspace.DevContainer => Resources.TypeWorkspaceDevContainer,
_ => string.Empty
};

}
}

Expand Down
2 changes: 1 addition & 1 deletion WorkspacesHelper/VSCodeWorkspacesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 5e4e1c5

Please sign in to comment.