Skip to content

Commit

Permalink
Merge pull request #12 from taooceros/remote_label
Browse files Browse the repository at this point in the history
Use Remote Label if possible
  • Loading branch information
taooceros authored Apr 6, 2024
2 parents df8d300 + d523f30 commit 07e2f4b
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v4
with:
dotnet-version: 5.0.x
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore -c Release
- name: Upload Artifact
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
with:
name: Flow.Plugin.VSCodeWorkSpace
path: Output/Release/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
bin/
obj/
Output/
install.nu
20 changes: 14 additions & 6 deletions Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ public List<Result> Query(Query query)
// User defined extra workspaces
if (defaultInstalce != null)
{
workspaces.AddRange(_settings.CustomWorkspaces.Select(uri => VSCodeWorkspacesApi.ParseVSCodeUri(uri, defaultInstalce)));
workspaces.AddRange(_settings.CustomWorkspaces.Select(uri =>
VSCodeWorkspacesApi.ParseVSCodeUri(uri, defaultInstalce)));
}

// Search opened workspaces
Expand Down Expand Up @@ -84,7 +85,8 @@ public List<Result> Query(Query query)
{
FileName = a.VSCodeInstance.ExecutablePath,
UseShellExecute = true,
Arguments = $"--new-window --enable-proposed-api ms-vscode-remote.remote-ssh --remote ssh-remote+{((char)34) + a.Host + ((char)34)}",
Arguments =
$"--new-window --enable-proposed-api ms-vscode-remote.remote-ssh --remote ssh-remote+{((char)34) + a.Host + ((char)34)}",
WindowStyle = ProcessWindowStyle.Hidden,
};
Process.Start(process);
Expand All @@ -106,7 +108,8 @@ public List<Result> Query(Query query)
});
}

if (query.ActionKeyword == string.Empty || (query.ActionKeyword != string.Empty && query.Search != string.Empty))
if (query.ActionKeyword == string.Empty ||
(query.ActionKeyword != string.Empty && query.Search != string.Empty))
{
results = results.Where(r =>
{
Expand All @@ -126,10 +129,13 @@ private Result CreateWorkspaceResult(VSCodeWorkspace ws)

if (ws.TypeWorkspace != TypeWorkspace.Local)
{
title = $"{title}{(ws.ExtraInfo != null ? $" - {ws.ExtraInfo}" : string.Empty)} ({typeWorkspace})";
title = ws.Lable != null
? $"{ws.Lable}"
: $"{title}{(ws.ExtraInfo != null ? $" - {ws.ExtraInfo}" : string.Empty)} ({typeWorkspace})";
}

var tooltip = $"{Resources.Workspace}{(ws.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : string.Empty)}: {SystemPath.RealPath(ws.RelativePath)}";
var tooltip =
$"{Resources.Workspace}{(ws.TypeWorkspace != TypeWorkspace.Local ? $" {Resources.In} {typeWorkspace}" : string.Empty)}: {SystemPath.RealPath(ws.RelativePath)}";

return new Result
{
Expand Down Expand Up @@ -166,6 +172,7 @@ private Result CreateWorkspaceResult(VSCodeWorkspace ws)
string msg = Resources.OpenFail;
_context.API.ShowMsg(name, msg, string.Empty);
}

return false;
},
ContextData = ws,
Expand Down Expand Up @@ -220,7 +227,8 @@ public List<Result> LoadContextMenus(Result selectedResult)
ContextData = ws,
});
}

return results;
}
}
}
}
2 changes: 2 additions & 0 deletions WorkspacesHelper/VSCodeWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public record VSCodeWorkspace
public PathString RelativePath { get; init; }

public PathString FolderName { get; init; }

public string Lable { get; init; }

public string ExtraInfo { get; init; }

Expand Down
25 changes: 19 additions & 6 deletions WorkspacesHelper/VSCodeWorkspacesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.RegularExpressions;
using Flow.Plugin.VSCodeWorkspaces.VSCodeHelper;
using Microsoft.Data.Sqlite;

Expand Down Expand Up @@ -50,6 +51,8 @@ public static VSCodeWorkspace ParseVSCodeUri(string uri, VSCodeInstance vscodeIn
return null;
}

public Regex workspaceLabelParser = new Regex("(.+?)(\\[.+\\])");

public List<VSCodeWorkspace> Workspaces
{
get
Expand Down Expand Up @@ -99,7 +102,8 @@ public List<VSCodeWorkspace> Workspaces
}

// for vscode v1.64.0 or later
using var connection = new SqliteConnection($"Data Source={vscodeInstance.AppData}/User/globalStorage/state.vscdb;mode=readonly;cache=shared;");
using var connection = new SqliteConnection(
$"Data Source={vscodeInstance.AppData}/User/globalStorage/state.vscdb;mode=readonly;cache=shared;");
connection.Open();
var command = connection.CreateCommand();
command.CommandText = "SELECT value FROM ItemTable where key = 'history.recentlyOpenedPathsList'";
Expand All @@ -115,17 +119,26 @@ public List<VSCodeWorkspace> Workspaces
if (!entry.TryGetProperty("folderUri", out var folderUri))
continue;
var workspaceUri = folderUri.GetString();
var uri = ParseVSCodeUri(workspaceUri, vscodeInstance);
if (uri == null)
var workspace = ParseVSCodeUri(workspaceUri, vscodeInstance);
if (workspace == null)
continue;
results.Add(uri);

if (entry.TryGetProperty("label", out var label))
{
var labelString = label.GetString()!;
var matchGroup = workspaceLabelParser.Match(labelString);
workspace = workspace with {
Lable = $"{matchGroup.Groups[2]} {matchGroup.Groups[1]}"
};
}

results.Add(workspace);
}
}

}

return results;
}
}
}
}
}
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"ActionKeyword": "{",
"Name": "VS Code Workspaces",
"Author": "ricardosantos9521",
"Version": "1.3.0",
"Version": "1.3.1",
"Language": "csharp",
"Website": "https://github.com/taooceros/Flow.Plugin.VSCodeWorkspace",
"ExecuteFileName": "Flow.Plugin.VSCodeWorkspaces.dll",
Expand Down

0 comments on commit 07e2f4b

Please sign in to comment.