#14931 Show previous opened VSCode workspaces (#15108)

This commit is contained in:
ricardosantos9521
2021-12-27 18:17:20 +00:00
committed by GitHub
parent 7b280ebde1
commit 5f9cf69a24
9 changed files with 101 additions and 51 deletions

View File

@@ -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)