Skip to content

Commit 07e2f4b

Browse files
authored
Merge pull request #12 from taooceros/remote_label
Use Remote Label if possible
2 parents df8d300 + d523f30 commit 07e2f4b

File tree

6 files changed

+41
-17
lines changed

6 files changed

+41
-17
lines changed

.github/workflows/build dotnet.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ jobs:
1111
runs-on: windows-latest
1212

1313
steps:
14-
- uses: actions/checkout@v2
14+
- uses: actions/checkout@v4
1515
- name: Setup .NET
16-
uses: actions/setup-dotnet@v1
16+
uses: actions/setup-dotnet@v4
1717
with:
18-
dotnet-version: 5.0.x
18+
dotnet-version: 7.0.x
1919
- name: Restore dependencies
2020
run: dotnet restore
2121
- name: Build
2222
run: dotnet build --no-restore -c Release
2323
- name: Upload Artifact
24-
uses: actions/upload-artifact@v2
24+
uses: actions/upload-artifact@v4
2525
with:
2626
name: Flow.Plugin.VSCodeWorkSpace
2727
path: Output/Release/

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
bin/
55
obj/
66
Output/
7+
install.nu

Main.cs

+14-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public List<Result> Query(Query query)
4141
// User defined extra workspaces
4242
if (defaultInstalce != null)
4343
{
44-
workspaces.AddRange(_settings.CustomWorkspaces.Select(uri => VSCodeWorkspacesApi.ParseVSCodeUri(uri, defaultInstalce)));
44+
workspaces.AddRange(_settings.CustomWorkspaces.Select(uri =>
45+
VSCodeWorkspacesApi.ParseVSCodeUri(uri, defaultInstalce)));
4546
}
4647

4748
// Search opened workspaces
@@ -84,7 +85,8 @@ public List<Result> Query(Query query)
8485
{
8586
FileName = a.VSCodeInstance.ExecutablePath,
8687
UseShellExecute = true,
87-
Arguments = $"--new-window --enable-proposed-api ms-vscode-remote.remote-ssh --remote ssh-remote+{((char)34) + a.Host + ((char)34)}",
88+
Arguments =
89+
$"--new-window --enable-proposed-api ms-vscode-remote.remote-ssh --remote ssh-remote+{((char)34) + a.Host + ((char)34)}",
8890
WindowStyle = ProcessWindowStyle.Hidden,
8991
};
9092
Process.Start(process);
@@ -106,7 +108,8 @@ public List<Result> Query(Query query)
106108
});
107109
}
108110

109-
if (query.ActionKeyword == string.Empty || (query.ActionKeyword != string.Empty && query.Search != string.Empty))
111+
if (query.ActionKeyword == string.Empty ||
112+
(query.ActionKeyword != string.Empty && query.Search != string.Empty))
110113
{
111114
results = results.Where(r =>
112115
{
@@ -126,10 +129,13 @@ private Result CreateWorkspaceResult(VSCodeWorkspace ws)
126129

127130
if (ws.TypeWorkspace != TypeWorkspace.Local)
128131
{
129-
title = $"{title}{(ws.ExtraInfo != null ? $" - {ws.ExtraInfo}" : string.Empty)} ({typeWorkspace})";
132+
title = ws.Lable != null
133+
? $"{ws.Lable}"
134+
: $"{title}{(ws.ExtraInfo != null ? $" - {ws.ExtraInfo}" : string.Empty)} ({typeWorkspace})";
130135
}
131136

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

134140
return new Result
135141
{
@@ -166,6 +172,7 @@ private Result CreateWorkspaceResult(VSCodeWorkspace ws)
166172
string msg = Resources.OpenFail;
167173
_context.API.ShowMsg(name, msg, string.Empty);
168174
}
175+
169176
return false;
170177
},
171178
ContextData = ws,
@@ -220,7 +227,8 @@ public List<Result> LoadContextMenus(Result selectedResult)
220227
ContextData = ws,
221228
});
222229
}
230+
223231
return results;
224232
}
225233
}
226-
}
234+
}

WorkspacesHelper/VSCodeWorkspace.cs

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ public record VSCodeWorkspace
1515
public PathString RelativePath { get; init; }
1616

1717
public PathString FolderName { get; init; }
18+
19+
public string Lable { get; init; }
1820

1921
public string ExtraInfo { get; init; }
2022

WorkspacesHelper/VSCodeWorkspacesApi.cs

+19-6
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.IO;
88
using System.Linq;
99
using System.Text.Json;
10+
using System.Text.RegularExpressions;
1011
using Flow.Plugin.VSCodeWorkspaces.VSCodeHelper;
1112
using Microsoft.Data.Sqlite;
1213

@@ -50,6 +51,8 @@ public static VSCodeWorkspace ParseVSCodeUri(string uri, VSCodeInstance vscodeIn
5051
return null;
5152
}
5253

54+
public Regex workspaceLabelParser = new Regex("(.+?)(\\[.+\\])");
55+
5356
public List<VSCodeWorkspace> Workspaces
5457
{
5558
get
@@ -99,7 +102,8 @@ public List<VSCodeWorkspace> Workspaces
99102
}
100103

101104
// for vscode v1.64.0 or later
102-
using var connection = new SqliteConnection($"Data Source={vscodeInstance.AppData}/User/globalStorage/state.vscdb;mode=readonly;cache=shared;");
105+
using var connection = new SqliteConnection(
106+
$"Data Source={vscodeInstance.AppData}/User/globalStorage/state.vscdb;mode=readonly;cache=shared;");
103107
connection.Open();
104108
var command = connection.CreateCommand();
105109
command.CommandText = "SELECT value FROM ItemTable where key = 'history.recentlyOpenedPathsList'";
@@ -115,17 +119,26 @@ public List<VSCodeWorkspace> Workspaces
115119
if (!entry.TryGetProperty("folderUri", out var folderUri))
116120
continue;
117121
var workspaceUri = folderUri.GetString();
118-
var uri = ParseVSCodeUri(workspaceUri, vscodeInstance);
119-
if (uri == null)
122+
var workspace = ParseVSCodeUri(workspaceUri, vscodeInstance);
123+
if (workspace == null)
120124
continue;
121-
results.Add(uri);
125+
126+
if (entry.TryGetProperty("label", out var label))
127+
{
128+
var labelString = label.GetString()!;
129+
var matchGroup = workspaceLabelParser.Match(labelString);
130+
workspace = workspace with {
131+
Lable = $"{matchGroup.Groups[2]} {matchGroup.Groups[1]}"
132+
};
133+
}
134+
135+
results.Add(workspace);
122136
}
123137
}
124-
125138
}
126139

127140
return results;
128141
}
129142
}
130143
}
131-
}
144+
}

plugin.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"ActionKeyword": "{",
55
"Name": "VS Code Workspaces",
66
"Author": "ricardosantos9521",
7-
"Version": "1.3.0",
7+
"Version": "1.3.1",
88
"Language": "csharp",
99
"Website": "https://github.com/taooceros/Flow.Plugin.VSCodeWorkspace",
1010
"ExecuteFileName": "Flow.Plugin.VSCodeWorkspaces.dll",

0 commit comments

Comments
 (0)