fix workspaces not showing in vscode plugin #10530 (#10533)

This commit is contained in:
ricardosantos9521
2021-04-02 14:06:14 +01:00
committed by GitHub
parent d128939227
commit 2b9ecf75b6
2 changed files with 53 additions and 15 deletions

View File

@@ -7,8 +7,16 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
public openedPathsList openedPathsList { get; set; } public openedPathsList openedPathsList { get; set; }
} }
public class VSCodeWorkspaceEntry
{
public string folderUri { get; set; }
public string label { get; set; }
}
public class openedPathsList public class openedPathsList
{ {
public List<dynamic> workspaces3 { get; set; } public List<dynamic> workspaces3 { get; set; }
public List<VSCodeWorkspaceEntry> entries { get; set; }
} }
} }

View File

@@ -3,6 +3,7 @@ using Newtonsoft.Json;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using Wox.Plugin.Logger; using Wox.Plugin.Logger;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
@@ -11,6 +12,30 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{ {
public VSCodeWorkspacesApi() { } public VSCodeWorkspacesApi() { }
private VSCodeWorkspace parseVSCodeUri(string uri, VSCodeInstance vscodeInstance)
{
if (uri != null && uri is String)
{
string unescapeUri = Uri.UnescapeDataString(uri);
var typeWorkspace = ParseVSCodeUri.GetTypeWorkspace(unescapeUri);
if (typeWorkspace.TypeWorkspace.HasValue)
{
var folderName = Path.GetFileName(unescapeUri);
return new VSCodeWorkspace()
{
Path = uri,
RelativePath = typeWorkspace.Path,
FolderName = folderName,
ExtraInfo = typeWorkspace.MachineName,
TypeWorkspace = typeWorkspace.TypeWorkspace.Value,
VSCodeInstance = vscodeInstance
};
}
}
return null;
}
public List<VSCodeWorkspace> Workspaces public List<VSCodeWorkspace> Workspaces
{ {
get get
@@ -33,27 +58,32 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
if (vscodeStorageFile != null) if (vscodeStorageFile != null)
{ {
foreach (var workspaceUri in vscodeStorageFile.openedPathsList.workspaces3) //for previous versions of vscode
if (vscodeStorageFile.openedPathsList.workspaces3 != null)
{ {
if (workspaceUri != null && workspaceUri is String) foreach (var workspaceUri in vscodeStorageFile.openedPathsList.workspaces3)
{ {
string unescapeUri = Uri.UnescapeDataString(workspaceUri); var uri = parseVSCodeUri(workspaceUri, vscodeInstance);
var typeWorkspace = ParseVSCodeUri.GetTypeWorkspace(unescapeUri); if (uri != null)
if (typeWorkspace.TypeWorkspace.HasValue)
{ {
var folderName = Path.GetFileName(unescapeUri); results.Add(uri);
results.Add(new VSCodeWorkspace()
{
Path = workspaceUri,
RelativePath = typeWorkspace.Path,
FolderName = folderName,
ExtraInfo = typeWorkspace.MachineName,
TypeWorkspace = typeWorkspace.TypeWorkspace.Value,
VSCodeInstance = vscodeInstance
});
} }
} }
} }
//vscode v1.55.0 or later
if (vscodeStorageFile.openedPathsList.entries != null)
{
foreach (var workspaceUri in vscodeStorageFile.openedPathsList.entries.Select(x => x.folderUri))
{
var uri = parseVSCodeUri(workspaceUri, vscodeInstance);
if (uri != null)
{
results.Add(uri);
}
}
}
} }
} }
catch (Exception ex) catch (Exception ex)