Skip to content

Commit

Permalink
fix workspaces not showing in vscode plugin #10530 (#10533)
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardosantos9521 committed Apr 2, 2021
1 parent d128939 commit 2b9ecf7
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ 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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Wox.Plugin.Logger;

namespace Community.PowerToys.Run.Plugin.VSCodeWorkspaces.WorkspacesHelper
Expand All @@ -11,6 +12,30 @@ public class 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
{
get
Expand All @@ -33,27 +58,32 @@ public List<VSCodeWorkspace> Workspaces

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 typeWorkspace = ParseVSCodeUri.GetTypeWorkspace(unescapeUri);
if (typeWorkspace.TypeWorkspace.HasValue)
var uri = parseVSCodeUri(workspaceUri, vscodeInstance);
if (uri != null)
{
var folderName = Path.GetFileName(unescapeUri);
results.Add(new VSCodeWorkspace()
{
Path = workspaceUri,
RelativePath = typeWorkspace.Path,
FolderName = folderName,
ExtraInfo = typeWorkspace.MachineName,
TypeWorkspace = typeWorkspace.TypeWorkspace.Value,
VSCodeInstance = vscodeInstance
});
results.Add(uri);
}
}
}

//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)
Expand Down

1 comment on commit 2b9ecf7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misspellings found, please review:

  • CHECKCANCELED
  • IProgress
  • ISmart
  • MARQUEEPROGRESS
  • PROGDLG
  • prpui
  • sppd
  • sppre
  • TIMERID
To accept these changes, run the following commands from this repository on this branch
pushd $(git rev-parse --show-toplevel)
perl -e '
my @expect_files=qw('".github/actions/spell-check/expect.txt"');
@ARGV=@expect_files;
my @stale=qw('"Devagya Drakula Oject RSHIFT YourUserName "');
my $re=join "|", @stale;
my $suffix=".".time();
my $previous="";
sub maybe_unlink { unlink($_[0]) if $_[0]; }
while (<>) {
  if ($ARGV ne $old_argv) { maybe_unlink($previous); $previous="$ARGV$suffix"; rename($ARGV, $previous); open(ARGV_OUT, ">$ARGV"); select(ARGV_OUT); $old_argv = $ARGV; }
  next if /^(?:$re)(?:(?:\r|\n)*$| .*)/; print;
}; maybe_unlink($previous);'
perl -e '
my $new_expect_file=".github/actions/spell-check/expect.txt";
use File::Path qw(make_path);
make_path ".github/actions/spell-check";
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"CHECKCANCELED IProgress ISmart MARQUEEPROGRESS PROGDLG prpui rshift sppd sppre TIMERID "');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a) cmp lc($b)} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;'
popd

Please sign in to comment.