mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 09:46:54 +02:00
committed by
GitHub
parent
7b280ebde1
commit
5f9cf69a24
@@ -41,20 +41,20 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
|
||||
// Search opened workspaces
|
||||
_workspacesApi.Workspaces.ForEach(a =>
|
||||
{
|
||||
var title = $"{a.FolderName}";
|
||||
var title = a.WorkspaceType == WorkspaceType.ProjectFolder ? a.FolderName : a.FolderName.Replace(".code-workspace", $" ({Resources.Workspace})");
|
||||
|
||||
var typeWorkspace = a.WorkspaceTypeToString();
|
||||
if (a.TypeWorkspace != TypeWorkspace.Local)
|
||||
var typeWorkspace = a.WorkspaceEnvironmentToString();
|
||||
if (a.WorkspaceEnvironment != WorkspaceEnvironment.Local)
|
||||
{
|
||||
title = $"{title}{(a.ExtraInfo != null ? $" - {a.ExtraInfo}" : string.Empty)} ({typeWorkspace})";
|
||||
}
|
||||
|
||||
var tooltip = new ToolTipData(title, $"{Resources.Workspace}{(a.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : string.Empty)}: {SystemPath.RealPath(a.RelativePath)}");
|
||||
var tooltip = new ToolTipData(title, $"{(a.WorkspaceType == WorkspaceType.WorkspaceFile ? Resources.Workspace : Resources.ProjectFolder)}{(a.WorkspaceEnvironment != WorkspaceEnvironment.Local ? $" {Resources.In} {typeWorkspace}" : string.Empty)}: {SystemPath.RealPath(a.RelativePath)}");
|
||||
|
||||
results.Add(new Result
|
||||
{
|
||||
Title = title,
|
||||
SubTitle = $"{Resources.Workspace}{(a.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : string.Empty)}: {SystemPath.RealPath(a.RelativePath)}",
|
||||
SubTitle = $"{(a.WorkspaceType == WorkspaceType.WorkspaceFile ? Resources.Workspace : Resources.ProjectFolder)}{(a.WorkspaceEnvironment != WorkspaceEnvironment.Local ? $" {Resources.In} {typeWorkspace}" : string.Empty)}: {SystemPath.RealPath(a.RelativePath)}",
|
||||
Icon = a.VSCodeInstance.WorkspaceIcon,
|
||||
ToolTipData = tooltip,
|
||||
Action = c =>
|
||||
@@ -66,7 +66,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
|
||||
{
|
||||
FileName = a.VSCodeInstance.ExecutablePath,
|
||||
UseShellExecute = true,
|
||||
Arguments = $"--folder-uri {a.Path}",
|
||||
Arguments = a.WorkspaceType == WorkspaceType.ProjectFolder ? $"--folder-uri {a.Path}" : $"--file-uri {a.Path}",
|
||||
WindowStyle = ProcessWindowStyle.Hidden,
|
||||
};
|
||||
Process.Start(process);
|
||||
@@ -142,23 +142,23 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces
|
||||
}
|
||||
|
||||
results.ForEach(x =>
|
||||
{
|
||||
if (x.Score == 0)
|
||||
{
|
||||
x.Score = 100;
|
||||
}
|
||||
{
|
||||
if (x.Score == 0)
|
||||
{
|
||||
x.Score = 100;
|
||||
}
|
||||
|
||||
// intersect the title with the query
|
||||
var intersection = Convert.ToInt32(x.Title.ToLowerInvariant().Intersect(query.Search.ToLowerInvariant()).Count() * query.Search.Count());
|
||||
var differenceWithQuery = Convert.ToInt32((x.Title.Count() - intersection) * query.Search.Count() * 0.7);
|
||||
x.Score = x.Score - differenceWithQuery + intersection;
|
||||
// intersect the title with the query
|
||||
var intersection = Convert.ToInt32(x.Title.ToLowerInvariant().Intersect(query.Search.ToLowerInvariant()).Count() * query.Search.Count());
|
||||
var differenceWithQuery = Convert.ToInt32((x.Title.Count() - intersection) * query.Search.Count() * 0.7);
|
||||
x.Score = x.Score - differenceWithQuery + intersection;
|
||||
|
||||
// if is a remote machine give it 12 extra points
|
||||
if (x.ContextData is VSCodeRemoteMachine)
|
||||
{
|
||||
x.Score = Convert.ToInt32(x.Score + (intersection * 2));
|
||||
}
|
||||
});
|
||||
// if is a remote machine give it 12 extra points
|
||||
if (x.ContextData is VSCodeRemoteMachine)
|
||||
{
|
||||
x.Score = Convert.ToInt32(x.Score + (intersection * 2));
|
||||
}
|
||||
});
|
||||
|
||||
results = results.OrderByDescending(x => x.Score).ToList();
|
||||
if (query.Search == string.Empty || query.Search.Replace(" ", string.Empty) == string.Empty)
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.Properties {
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
@@ -87,6 +87,15 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Project Folder.
|
||||
/// </summary>
|
||||
internal static string ProjectFolder {
|
||||
get {
|
||||
return ResourceManager.GetString("ProjectFolder", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to SSH remote machine.
|
||||
/// </summary>
|
||||
|
||||
@@ -140,10 +140,14 @@
|
||||
</data>
|
||||
<data name="Workspace" xml:space="preserve">
|
||||
<value>Workspace</value>
|
||||
<comment>It refers to the "Visual Studio Code workspace"</comment>
|
||||
<comment>It refers to the Visual Studio Code .code-workspace</comment>
|
||||
</data>
|
||||
<data name="TypeWorkspaceDevContainer" xml:space="preserve">
|
||||
<value>Dev Container</value>
|
||||
<comment>As in "Visual Studio Code Dev Container workspace "</comment>
|
||||
</data>
|
||||
<data name="ProjectFolder" xml:space="preserve">
|
||||
<value>Project Folder</value>
|
||||
<comment>It refers to the Visual Studio Code Project Folders</comment>
|
||||
</data>
|
||||
</root>
|
||||
@@ -18,7 +18,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
|
||||
private static readonly Regex DevContainerWorkspace = new Regex(@"^vscode-remote://dev-container\+(.+?(?=\/))(.+)$", RegexOptions.Compiled);
|
||||
|
||||
public static (TypeWorkspace? TypeWorkspace, string MachineName, string Path) GetTypeWorkspace(string uri)
|
||||
public static (WorkspaceEnvironment? WorkspaceEnvironment, string MachineName, string Path) GetWorkspaceEnvironment(string uri)
|
||||
{
|
||||
if (LocalWorkspace.IsMatch(uri))
|
||||
{
|
||||
@@ -26,7 +26,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
|
||||
if (match.Groups.Count > 1)
|
||||
{
|
||||
return (TypeWorkspace.Local, null, match.Groups[1].Value);
|
||||
return (WorkspaceEnvironment.Local, null, match.Groups[1].Value);
|
||||
}
|
||||
}
|
||||
else if (RemoteSSHWorkspace.IsMatch(uri))
|
||||
@@ -35,7 +35,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
|
||||
if (match.Groups.Count > 1)
|
||||
{
|
||||
return (TypeWorkspace.RemoteSSH, match.Groups[1].Value, match.Groups[2].Value);
|
||||
return (WorkspaceEnvironment.RemoteSSH, match.Groups[1].Value, match.Groups[2].Value);
|
||||
}
|
||||
}
|
||||
else if (RemoteWSLWorkspace.IsMatch(uri))
|
||||
@@ -44,7 +44,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
|
||||
if (match.Groups.Count > 1)
|
||||
{
|
||||
return (TypeWorkspace.RemoteWSL, match.Groups[1].Value, match.Groups[2].Value);
|
||||
return (WorkspaceEnvironment.RemoteWSL, match.Groups[1].Value, match.Groups[2].Value);
|
||||
}
|
||||
}
|
||||
else if (CodespacesWorkspace.IsMatch(uri))
|
||||
@@ -53,7 +53,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
|
||||
if (match.Groups.Count > 1)
|
||||
{
|
||||
return (TypeWorkspace.Codespaces, null, match.Groups[2].Value);
|
||||
return (WorkspaceEnvironment.Codespaces, null, match.Groups[2].Value);
|
||||
}
|
||||
}
|
||||
else if (DevContainerWorkspace.IsMatch(uri))
|
||||
@@ -62,7 +62,7 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
|
||||
if (match.Groups.Count > 1)
|
||||
{
|
||||
return (TypeWorkspace.DevContainer, null, match.Groups[2].Value);
|
||||
return (WorkspaceEnvironment.DevContainer, null, match.Groups[2].Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -17,27 +17,29 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
|
||||
public string ExtraInfo { get; set; }
|
||||
|
||||
public TypeWorkspace TypeWorkspace { get; set; }
|
||||
public WorkspaceEnvironment WorkspaceEnvironment { get; set; }
|
||||
|
||||
public WorkspaceType WorkspaceType { get; set; }
|
||||
|
||||
public VSCodeInstance VSCodeInstance { get; set; }
|
||||
|
||||
public string WorkspaceTypeToString()
|
||||
public string WorkspaceEnvironmentToString()
|
||||
{
|
||||
switch (TypeWorkspace)
|
||||
switch (WorkspaceEnvironment)
|
||||
{
|
||||
case TypeWorkspace.Local: return Resources.TypeWorkspaceLocal;
|
||||
case TypeWorkspace.Codespaces: return "Codespaces";
|
||||
case TypeWorkspace.RemoteContainers: return Resources.TypeWorkspaceContainer;
|
||||
case TypeWorkspace.RemoteSSH: return "SSH";
|
||||
case TypeWorkspace.RemoteWSL: return "WSL";
|
||||
case TypeWorkspace.DevContainer: return Resources.TypeWorkspaceDevContainer;
|
||||
case WorkspaceEnvironment.Local: return Resources.TypeWorkspaceLocal;
|
||||
case WorkspaceEnvironment.Codespaces: return "Codespaces";
|
||||
case WorkspaceEnvironment.RemoteContainers: return Resources.TypeWorkspaceContainer;
|
||||
case WorkspaceEnvironment.RemoteSSH: return "SSH";
|
||||
case WorkspaceEnvironment.RemoteWSL: return "WSL";
|
||||
case WorkspaceEnvironment.DevContainer: return Resources.TypeWorkspaceDevContainer;
|
||||
}
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public enum TypeWorkspace
|
||||
public enum WorkspaceEnvironment
|
||||
{
|
||||
Local = 1,
|
||||
Codespaces = 2,
|
||||
@@ -46,4 +48,10 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
RemoteContainers = 5,
|
||||
DevContainer = 6,
|
||||
}
|
||||
|
||||
public enum WorkspaceType
|
||||
{
|
||||
ProjectFolder = 1,
|
||||
WorkspaceFile = 2,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,5 +13,8 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
|
||||
[JsonPropertyName("label")]
|
||||
public string Label { get; set; }
|
||||
|
||||
[JsonPropertyName("workspace")]
|
||||
public VSCodeWorkspaceProperty Workspace { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
// 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.Json.Serialization;
|
||||
|
||||
namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
{
|
||||
public class VSCodeWorkspaceProperty
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public string Id { get; set; }
|
||||
|
||||
[JsonPropertyName("configPath")]
|
||||
public string ConfigPath { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -18,13 +18,13 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
{
|
||||
}
|
||||
|
||||
private VSCodeWorkspace ParseVSCodeUri(string uri, VSCodeInstance vscodeInstance)
|
||||
private VSCodeWorkspace ParseVSCodeUri(string uri, VSCodeInstance vscodeInstance, bool isWorkspaceFile = false)
|
||||
{
|
||||
if (uri != null && uri is string)
|
||||
{
|
||||
string unescapeUri = Uri.UnescapeDataString(uri);
|
||||
var typeWorkspace = WorkspacesHelper.ParseVSCodeUri.GetTypeWorkspace(unescapeUri);
|
||||
if (typeWorkspace.TypeWorkspace.HasValue)
|
||||
var typeWorkspace = WorkspacesHelper.ParseVSCodeUri.GetWorkspaceEnvironment(unescapeUri);
|
||||
if (typeWorkspace.WorkspaceEnvironment.HasValue)
|
||||
{
|
||||
var folderName = Path.GetFileName(unescapeUri);
|
||||
|
||||
@@ -38,10 +38,11 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
return new VSCodeWorkspace()
|
||||
{
|
||||
Path = uri,
|
||||
WorkspaceType = isWorkspaceFile ? WorkspaceType.WorkspaceFile : WorkspaceType.ProjectFolder,
|
||||
RelativePath = typeWorkspace.Path,
|
||||
FolderName = folderName,
|
||||
ExtraInfo = typeWorkspace.MachineName,
|
||||
TypeWorkspace = typeWorkspace.TypeWorkspace.Value,
|
||||
WorkspaceEnvironment = typeWorkspace.WorkspaceEnvironment.Value,
|
||||
VSCodeInstance = vscodeInstance,
|
||||
};
|
||||
}
|
||||
@@ -76,10 +77,10 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
{
|
||||
foreach (var workspaceUri in vscodeStorageFile.OpenedPathsList.Workspaces3)
|
||||
{
|
||||
var uri = ParseVSCodeUri(workspaceUri, vscodeInstance);
|
||||
if (uri != null)
|
||||
var workspace = ParseVSCodeUri(workspaceUri, vscodeInstance);
|
||||
if (workspace != null)
|
||||
{
|
||||
results.Add(uri);
|
||||
results.Add(workspace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -87,12 +88,20 @@ namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
|
||||
// vscode v1.55.0 or later
|
||||
if (vscodeStorageFile.OpenedPathsList.Entries != null)
|
||||
{
|
||||
foreach (var workspaceUri in vscodeStorageFile.OpenedPathsList.Entries.Select(x => x.FolderUri))
|
||||
foreach (var entry in vscodeStorageFile.OpenedPathsList.Entries)
|
||||
{
|
||||
var uri = ParseVSCodeUri(workspaceUri, vscodeInstance);
|
||||
if (uri != null)
|
||||
bool isWorkspaceFile = false;
|
||||
var uri = entry.FolderUri;
|
||||
if (entry.Workspace != null && entry.Workspace.ConfigPath != null)
|
||||
{
|
||||
results.Add(uri);
|
||||
isWorkspaceFile = true;
|
||||
uri = entry.Workspace.ConfigPath;
|
||||
}
|
||||
|
||||
var workspace = ParseVSCodeUri(uri, vscodeInstance, isWorkspaceFile);
|
||||
if (workspace != null)
|
||||
{
|
||||
results.Add(workspace);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
"ActionKeyword": "{",
|
||||
"Name": "VS Code Workspaces",
|
||||
"Author": "ricardosantos9521",
|
||||
"Version": "1.0.0",
|
||||
"Version": "1.1.0",
|
||||
"Language": "csharp",
|
||||
"Website": "https://github.com/ricardosantos9521/PowerToys/",
|
||||
"ExecuteFileName": "Community.PowerToys.Run.Plugin.VSCodeWorkspaces.dll",
|
||||
|
||||
Reference in New Issue
Block a user