From 45a3936e46fdc95f589a069728f1235050298c54 Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 11 Feb 2026 11:26:46 +0800 Subject: [PATCH] feature: support to open VSCode workspace (#2119) Signed-off-by: leo --- src/Models/ExternalTool.cs | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/Models/ExternalTool.cs b/src/Models/ExternalTool.cs index b0bdfb8b..5134f6fb 100644 --- a/src/Models/ExternalTool.cs +++ b/src/Models/ExternalTool.cs @@ -166,17 +166,17 @@ namespace SourceGit.Models public void VSCode(Func platformFinder) { - TryAdd("Visual Studio Code", "vscode", platformFinder); + TryAdd("Visual Studio Code", "vscode", platformFinder, GenerateVSCodeLaunchOptions); } public void VSCodeInsiders(Func platformFinder) { - TryAdd("Visual Studio Code - Insiders", "vscode_insiders", platformFinder); + TryAdd("Visual Studio Code - Insiders", "vscode_insiders", platformFinder, GenerateVSCodeLaunchOptions); } public void VSCodium(Func platformFinder) { - TryAdd("VSCodium", "codium", platformFinder); + TryAdd("VSCodium", "codium", platformFinder, GenerateVSCodeLaunchOptions); } public void SublimeText(Func platformFinder) @@ -223,6 +223,32 @@ namespace SourceGit.Models } } + private List GenerateVSCodeLaunchOptions(string path) + { + if (!Directory.Exists(path)) + return null; + + void Search(List opts, DirectoryInfo dir, string root, int depth) + { + if (depth < 0) + return; + + foreach (var file in dir.GetFiles()) + { + if (file.Name.EndsWith(".code-workspace", StringComparison.OrdinalIgnoreCase)) + opts.Add(new(Path.GetRelativePath(root, file.FullName), file.FullName.Quoted())); + } + + foreach (var subDir in dir.GetDirectories()) + Search(opts, subDir, root, depth - 1); + } + + var rootDir = new DirectoryInfo(path); + var options = new List(); + Search(options, rootDir, rootDir.FullName, 4); + return options; + } + private ExternalToolCustomization _customization = null; } }