Skip to content

Commit

Permalink
microsoft#15247 Powertoys Run | VSCodeWorkspaces- add support for vsc…
Browse files Browse the repository at this point in the history
…ode 1.64 new workspace.json file
  • Loading branch information
ricardosantos9521 committed Jan 18, 2022
1 parent 167ec5a commit 6fad85d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{
// v1.64 uses AppData\Roaming\Code\Backups\workspaces
public class VSCodeStorageWorkspaceFile
{
[JsonPropertyName("folderWorkspaceInfos")]
public List<VSCodeWorkspaceEntry> FolderWorkspaceInfos { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public List<VSCodeWorkspace> Workspaces
// storage.json contains opened Workspaces
var vscode_storage = Path.Combine(vscodeInstance.AppData, "storage.json");

// Backups/workspace.json - vscode v1.64 or later
var vscode_storage_workspaces = Path.Combine(vscodeInstance.AppData, "Backups/workspaces.json");

if (File.Exists(vscode_storage))
{
var fileContent = File.ReadAllText(vscode_storage);
Expand All @@ -70,7 +73,7 @@ public List<VSCodeWorkspace> Workspaces
{
VSCodeStorageFile vscodeStorageFile = JsonSerializer.Deserialize<VSCodeStorageFile>(fileContent);

if (vscodeStorageFile != null)
if (vscodeStorageFile != null && vscodeStorageFile.OpenedPathsList != null)
{
// for previous versions of vscode
if (vscodeStorageFile.OpenedPathsList.Workspaces3 != null)
Expand Down Expand Up @@ -98,6 +101,32 @@ public List<VSCodeWorkspace> Workspaces
uri = entry.Workspace.ConfigPath;
}

var workspace = ParseVSCodeUri(uri, vscodeInstance, isWorkspaceFile);
if (workspace != null)
{
results.Add(workspace);
}
}
}
}
else if (File.Exists(vscode_storage_workspaces))
{
// vscode 1.64 or later
fileContent = File.ReadAllText(vscode_storage_workspaces);
VSCodeStorageWorkspaceFile vscodeStorageWorkspaceFile = JsonSerializer.Deserialize<VSCodeStorageWorkspaceFile>(fileContent);

if (vscodeStorageWorkspaceFile.FolderWorkspaceInfos != null)
{
foreach (var entry in vscodeStorageWorkspaceFile.FolderWorkspaceInfos)
{
bool isWorkspaceFile = false;
var uri = entry.FolderUri;
if (entry.Workspace != null && entry.Workspace.ConfigPath != null)
{
isWorkspaceFile = true;
uri = entry.Workspace.ConfigPath;
}

var workspace = ParseVSCodeUri(uri, vscodeInstance, isWorkspaceFile);
if (workspace != null)
{
Expand Down

0 comments on commit 6fad85d

Please sign in to comment.