[PowerToys Run] Plugins StyleCop and warnings fix (#12623)

This commit is contained in:
Davide Giacometti
2021-08-11 17:22:30 +02:00
committed by GitHub
parent 7ea1f26209
commit 1791246a79
25 changed files with 251 additions and 128 deletions

View File

@@ -0,0 +1,15 @@
// 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;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{
public class OpenedPathsList
{
public List<dynamic> Workspaces3 { get; set; }
public List<VSCodeWorkspaceEntry> Entries { get; set; }
}
}

View File

@@ -1,4 +1,7 @@
using System;
// 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.Text.RegularExpressions;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
@@ -13,7 +16,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
private static readonly Regex CodespacesWorkspace = new Regex(@"^vscode-remote://vsonline\+(.+?(?=\/))(.+)$", RegexOptions.Compiled);
public static (TypeWorkspace? TypeWorkspace, String MachineName, String Path) GetTypeWorkspace(string uri)
public static (TypeWorkspace? TypeWorkspace, string MachineName, string Path) GetTypeWorkspace(string uri)
{
if (LocalWorkspace.IsMatch(uri))
{
@@ -48,7 +51,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
if (match.Groups.Count > 1)
{
return (TypeWorkspace.Codespaces, String.Empty, match.Groups[2].Value);
return (TypeWorkspace.Codespaces, string.Empty, match.Groups[2].Value);
}
}

View File

@@ -1,22 +1,11 @@
using System.Collections.Generic;
// 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.
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{
public class VSCodeStorageFile
{
public openedPathsList openedPathsList { get; set; }
}
public class VSCodeWorkspaceEntry
{
public string folderUri { get; set; }
public string label { get; set; }
}
public class openedPathsList
{
public List<dynamic> workspaces3 { get; set; }
public List<VSCodeWorkspaceEntry> entries { get; set; }
public OpenedPathsList OpenedPathsList { get; set; }
}
}

View File

@@ -1,4 +1,8 @@
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.Properties;
// 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 Community.PowerToys.Run.Plugin.VSCodeWorkspaces.Properties;
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
@@ -38,6 +42,6 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
Codespaces = 2,
RemoteWSL = 3,
RemoteSSH = 4,
RemoteContainers = 5
RemoteContainers = 5,
}
}

View File

@@ -0,0 +1,13 @@
// 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.
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{
public class VSCodeWorkspaceEntry
{
public string FolderUri { get; set; }
public string Label { get; set; }
}
}

View File

@@ -1,23 +1,29 @@
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;
using Newtonsoft.Json;
// 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;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using Community.PowerToys.Run.Plugin.VSCodeWorkspaces.VSCodeHelper;
using Wox.Plugin.Logger;
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{
public class VSCodeWorkspacesApi
{
public VSCodeWorkspacesApi() { }
private VSCodeWorkspace parseVSCodeUri(string uri, VSCodeInstance vscodeInstance)
public VSCodeWorkspacesApi()
{
if (uri != null && uri is String)
}
private VSCodeWorkspace ParseVSCodeUri(string uri, VSCodeInstance vscodeInstance)
{
if (uri != null && uri is string)
{
string unescapeUri = Uri.UnescapeDataString(uri);
var typeWorkspace = ParseVSCodeUri.GetTypeWorkspace(unescapeUri);
var typeWorkspace = WorkspacesHelper.ParseVSCodeUri.GetTypeWorkspace(unescapeUri);
if (typeWorkspace.TypeWorkspace.HasValue)
{
var folderName = Path.GetFileName(unescapeUri);
@@ -28,7 +34,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
FolderName = folderName,
ExtraInfo = typeWorkspace.MachineName,
TypeWorkspace = typeWorkspace.TypeWorkspace.Value,
VSCodeInstance = vscodeInstance
VSCodeInstance = vscodeInstance,
};
}
}
@@ -40,10 +46,9 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
{
get
{
var results = new List<VSCodeWorkspace>();
foreach (var vscodeInstance in VSCodeInstances.instances)
foreach (var vscodeInstance in VSCodeInstances.Instances)
{
// storage.json contains opened Workspaces
var vscode_storage = Path.Combine(vscodeInstance.AppData, "storage.json");
@@ -54,16 +59,21 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
try
{
VSCodeStorageFile vscodeStorageFile = JsonConvert.DeserializeObject<VSCodeStorageFile>(fileContent);
var options = new JsonSerializerOptions
{
PropertyNameCaseInsensitive = true,
};
VSCodeStorageFile vscodeStorageFile = JsonSerializer.Deserialize<VSCodeStorageFile>(fileContent, options);
if (vscodeStorageFile != null)
{
//for previous versions of vscode
if (vscodeStorageFile.openedPathsList.workspaces3 != null)
// for previous versions of vscode
if (vscodeStorageFile.OpenedPathsList.Workspaces3 != null)
{
foreach (var workspaceUri in vscodeStorageFile.openedPathsList.workspaces3)
foreach (var workspaceUri in vscodeStorageFile.OpenedPathsList.Workspaces3)
{
var uri = parseVSCodeUri(workspaceUri, vscodeInstance);
var uri = ParseVSCodeUri(workspaceUri, vscodeInstance);
if (uri != null)
{
results.Add(uri);
@@ -71,19 +81,18 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
}
}
//vscode v1.55.0 or later
if (vscodeStorageFile.openedPathsList.entries != null)
// vscode v1.55.0 or later
if (vscodeStorageFile.OpenedPathsList.Entries != null)
{
foreach (var workspaceUri in vscodeStorageFile.openedPathsList.entries.Select(x => x.folderUri))
foreach (var workspaceUri in vscodeStorageFile.OpenedPathsList.Entries.Select(x => x.FolderUri))
{
var uri = parseVSCodeUri(workspaceUri, vscodeInstance);
var uri = ParseVSCodeUri(workspaceUri, vscodeInstance);
if (uri != null)
{
results.Add(uri);
}
}
}
}
}
catch (Exception ex)
@@ -91,12 +100,9 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
var message = $"Failed to deserialize ${vscode_storage}";
Log.Exception(message, ex, GetType());
}
}
}
return results;
}
}