using Microsoft.CommandPalette.Extensions.Toolkit; namespace CmdPalVsCode; /// /// Command to open a Visual Studio Code workspace. /// internal sealed partial class OpenVSCodeCommand : InvokableCommand { public override string Name => "Open VS Code"; private string workspacePath; private string executablePath; private VSCodePage page; private string commandResult; /// /// Initializes a new instance of the class. /// /// The path to the VS Code executable. /// The path to the workspace to open. /// The VS Code page instance. /// The command result setting value. public OpenVSCodeCommand(string executablePath, string workspacePath, VSCodePage page, string commandResult) { this.workspacePath = workspacePath; this.executablePath = executablePath; this.page = page; this.commandResult = commandResult; } /// /// Invokes the command to open the workspace in VS Code. /// /// The result of the command execution. public override CommandResult Invoke() { string? arguments; // Open the workspace in VS Code if (workspacePath.EndsWith(".code-workspace", System.StringComparison.OrdinalIgnoreCase)) { arguments = $"--file-uri \"{workspacePath}\""; } else { arguments = $"--folder-uri \"{workspacePath}\""; } ShellHelpers.OpenInShell(executablePath, arguments, null, ShellHelpers.ShellRunAsType.None, false); VSCodePage.LoadItems = true; switch (commandResult) { case "GoBack": return CommandResult.GoBack(); case "KeepOpen": // reset search text page.UpdateSearchText(page.SearchText, ""); page.SearchText = ""; return CommandResult.KeepOpen(); case "Dismiss": default: return CommandResult.Dismiss(); } } }