Skip to content

Commit 9a55929

Browse files
Merge pull request #19 from JonahFintzDev/18-workspaces-arent-getting-populated-maybe-because-of-user-setup-installation
feat: improve performance and add support for custom vs code install …
2 parents 46c1b10 + 2b71cda commit 9a55929

File tree

7 files changed

+182
-55
lines changed

7 files changed

+182
-55
lines changed

VsCode/Classes/VSCodeHandler.cs

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,79 @@ public static void LoadInstances(string preferredEdition)
3030
AddInstance("VS Code - Insiders", Path.Combine(appdataProgramFilesPath, "Programs", "Microsoft VS Code Insiders", "Code - Insiders.exe"), insiderStoragePath, VSCodeInstallationType.User, VSCodeType.Insider);
3131
AddInstance("VS Code - Insiders [System]", Path.Combine(programsFolderPathBase, "Microsoft VS Code Insiders", "Code - Insiders.exe"), insiderStoragePath, VSCodeInstallationType.System, VSCodeType.Insider);
3232

33+
// search for custom installations in PATH environment variable
34+
try
35+
{
36+
var pathEnv = Environment.GetEnvironmentVariable("PATH");
37+
if (!string.IsNullOrEmpty(pathEnv))
38+
{
39+
var paths = pathEnv.Split(Path.PathSeparator, StringSplitOptions.RemoveEmptyEntries);
40+
foreach (var dir in paths)
41+
{
42+
43+
// get parent directory of the current directory
44+
if (string.IsNullOrEmpty(dir) || !Directory.Exists(dir))
45+
{
46+
continue;
47+
}
48+
var parentDir = Path.GetDirectoryName(dir) ?? dir;
49+
try
50+
{
51+
var codeExe = Path.Combine(parentDir, "code.exe");
52+
var codeInsidersExe = Path.Combine(parentDir, "Code - Insiders.exe");
53+
54+
if (File.Exists(codeExe))
55+
{
56+
AddInstance("VS Code [Custom]", codeExe, defaultStoragePath, VSCodeInstallationType.User, VSCodeType.Default);
57+
}
58+
if (File.Exists(codeInsidersExe))
59+
{
60+
AddInstance("VS Code - Insiders [Custom]", codeInsidersExe, insiderStoragePath, VSCodeInstallationType.User, VSCodeType.Insider);
61+
}
62+
}
63+
catch
64+
{
65+
// ignore any errors while checking for custom installations
66+
}
67+
}
68+
}
69+
}
70+
catch
71+
{
72+
// ignore invalid PATH entries
73+
}
3374

3475
if (preferredEdition == "Insider")
3576
{
36-
// Reverse the order of the instances
37-
Instances.Reverse();
77+
// sort instances to have insiders first
78+
Instances.Sort((x, y) =>
79+
{
80+
if (x.VSCodeType == VSCodeType.Insider && y.VSCodeType != VSCodeType.Insider)
81+
{
82+
return -1;
83+
}
84+
else if (x.VSCodeType != VSCodeType.Insider && y.VSCodeType == VSCodeType.Insider)
85+
{
86+
return 1;
87+
}
88+
return 0;
89+
});
90+
}
91+
else
92+
{
93+
// sort instances to have default first
94+
Instances.Sort((x, y) =>
95+
{
96+
if (x.VSCodeType == VSCodeType.Default && y.VSCodeType != VSCodeType.Default)
97+
{
98+
return -1;
99+
}
100+
else if (x.VSCodeType != VSCodeType.Default && y.VSCodeType == VSCodeType.Default)
101+
{
102+
return 1;
103+
}
104+
return 0;
105+
});
38106
}
39107
}
40108

@@ -50,6 +118,11 @@ private static void AddInstance(string name, string path, string storagePath, VS
50118
{
51119
if (File.Exists(path))
52120
{
121+
// check if there is already an instance with the same executable path
122+
if (Instances.Exists(instance => instance.ExecutablePath.Equals(path, StringComparison.OrdinalIgnoreCase)))
123+
{
124+
return; // Instance already exists
125+
}
53126
Instances.Add(new VSCodeInstance(name, path, storagePath, type, codeType));
54127
}
55128
}

VsCode/Classes/VSCodeInstance.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ internal class VSCodeInstance
3131
public string StoragePath;
3232
public VSCodeInstallationType InstallationType;
3333
public VSCodeType VSCodeType;
34+
public IconInfo Icon;
3435

3536
/// <summary>
3637
/// Initializes a new instance of the <see cref="VSCodeInstance"/> class.
@@ -47,13 +48,15 @@ public VSCodeInstance(string name, string executablePath, string storagePath, VS
4748
this.StoragePath = storagePath;
4849
this.InstallationType = installationType;
4950
this.VSCodeType = type;
51+
this.Icon = GetIcon();
52+
5053
}
5154

5255
/// <summary>
5356
/// Gets the icon associated with the VS Code instance.
5457
/// </summary>
5558
/// <returns>An icon representing the VS Code instance.</returns>
56-
public IIconInfo GetIcon()
59+
private IconInfo GetIcon()
5760
{
5861
switch (VSCodeType)
5962
{

VsCode/Classes/VSCodeWorkspace.cs

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ internal class VSCodeWorkspace
2323
public VSCodeInstance Instance;
2424
public string Path;
2525
public VSCodeWorkspaceType VSCodeWorkspaceType;
26+
public string WorkspaceName = "";
27+
public string VSTypeString = "";
28+
public string WorkspaceTypeString = "";
29+
public DetailsElement[] Details = [];
2630

2731
/// <summary>
2832
/// Initializes a new instance of the <see cref="VSCodeWorkspace"/> class.
@@ -34,72 +38,76 @@ public VSCodeWorkspace(VSCodeInstance instance, string path, VSCodeWorkspaceType
3438
this.Path = path;
3539
this.Instance = instance;
3640
this.VSCodeWorkspaceType = vsCodeWorkspaceType;
41+
42+
SetName();
43+
SetVSType();
44+
SetWorkspaceType();
45+
SetMetadata();
3746
}
3847

3948
/// <summary>
40-
/// Gets the name of the workspace.
49+
/// Sets the name of the workspace.
4150
/// </summary>
4251
/// <returns>The name of the workspace.</returns>
43-
public string GetName()
52+
public void SetName()
4453
{
45-
string workspaceName = "";
54+
WorkspaceName = "";
4655

4756
// split name by / and get last part
4857
var nameParts = Uri.UnescapeDataString(Path).Split('/');
4958
if (nameParts.Length == 0)
5059
{
51-
return workspaceName;
60+
return;
5261
}
5362

54-
workspaceName = nameParts[nameParts.Length - 1];
63+
WorkspaceName = nameParts[nameParts.Length - 1];
5564

5665
if (VSCodeWorkspaceType == VSCodeWorkspaceType.Workspace)
5766
{
5867
// remove .code-workspace
59-
workspaceName = workspaceName.Replace(".code-workspace", "");
68+
WorkspaceName = WorkspaceName.Replace(".code-workspace", "");
6069

6170
// if the workspace name is "workspace", use the folder name instead
62-
if (workspaceName == "workspace" && nameParts.Length >= 2)
71+
if (WorkspaceName == "workspace" && nameParts.Length >= 2)
6372
{
64-
workspaceName = nameParts[nameParts.Length - 2];
73+
WorkspaceName = nameParts[nameParts.Length - 2];
6574
}
6675
}
67-
68-
return workspaceName;
6976
}
7077

7178
/// <summary>
7279
/// Determines the type of the workspace (e.g., Local, WSL, Remote).
7380
/// </summary>
7481
/// <returns>The type of the workspace as a string.</returns>
75-
public string GetVSType()
82+
public void SetVSType()
7683
{
7784
if (Path.StartsWith("vscode-remote://wsl", System.StringComparison.OrdinalIgnoreCase))
7885
{
79-
return "WSL";
86+
VSTypeString = "WSL";
8087
}
8188
else if (Path.StartsWith("vscode-remote://", System.StringComparison.OrdinalIgnoreCase))
8289
{
83-
return "Remote";
90+
VSTypeString = "Remote";
8491
}
85-
86-
return "";
8792
}
8893

8994
/// <summary>
90-
/// Gets the workspace type (e.g., Workspace, Folder).
95+
/// Sets the workspace type (e.g., Workspace, Folder).
9196
/// </summary>
9297
/// <returns>The type of the workspace as a string.</returns>
93-
public string GetWorkspaceType()
98+
public void SetWorkspaceType()
9499
{
95100
switch (VSCodeWorkspaceType)
96101
{
97102
case VSCodeWorkspaceType.Workspace:
98-
return "Workspace";
103+
WorkspaceTypeString = "Workspace";
104+
break;
99105
case VSCodeWorkspaceType.Folder:
100-
return "Folder";
106+
WorkspaceTypeString = "Folder";
107+
break;
101108
default:
102-
return "Unknown Type";
109+
WorkspaceTypeString = "Unknown Type";
110+
break;
103111
}
104112
}
105113

@@ -108,15 +116,15 @@ public string GetWorkspaceType()
108116
/// Gets the details of the workspace.
109117
/// </summary>
110118
/// <returns>An array of details elements containing information about the workspace.</returns>
111-
public DetailsElement[] GetMetadata()
119+
public void SetMetadata()
112120
{
113-
var typeTags = new List<Tag>() { new Tag(GetWorkspaceType()) };
114-
if (GetVSType() != "")
121+
var typeTags = new List<Tag>() { new Tag(WorkspaceTypeString) };
122+
if (VSTypeString != "")
115123
{
116-
typeTags.Add(new Tag(GetVSType()));
124+
typeTags.Add(new Tag(VSTypeString));
117125
}
118126

119-
return new List<DetailsElement>(){
127+
Details = new List<DetailsElement>(){
120128
new DetailsElement()
121129
{
122130
Key = Resource.item_details_target,

VsCode/CmdPalVsCode.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
<AppxBundlePlatforms>x86|x64|arm64</AppxBundlePlatforms>
196196
<HoursBetweenUpdateChecks>0</HoursBetweenUpdateChecks>
197197
<GenerateTemporaryStoreCertificate>True</GenerateTemporaryStoreCertificate>
198-
<AppxPackageDir>I:\Freelancer\RiderProjects\CommandPaletteVSCode\AppPackages\</AppxPackageDir>
198+
<AppxPackageDir>G:\.net\CommandPaletteVSCode\AppPackages\</AppxPackageDir>
199199
</PropertyGroup>
200200

201201
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">

VsCode/Commands/OpenVsCodeCommand.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public override CommandResult Invoke()
4747
page.UpdateSearchText(page.SearchText, "");
4848
page.SearchText = "";
4949

50-
return CommandResult.Hide();
50+
VSCodePage.LoadItems = true;
51+
52+
return CommandResult.GoHome();
5153
}
5254
}

VsCode/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<Identity
1313
Name="JonahFintzDEV.602808C55E867"
1414
Publisher="CN=240FD63B-E96D-4F79-A6D2-BFC6E6AD6C10"
15-
Version="1.4.2.0" />
15+
Version="1.5.0.0" />
1616

1717
<Properties>
1818
<DisplayName>Command Palette - VS Code</DisplayName>

0 commit comments

Comments
 (0)