|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the VS Code Swift open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2025 the VS Code Swift project authors |
| 6 | +// Licensed under Apache License v2.0 |
| 7 | +// |
| 8 | +// See LICENSE.txt for license information |
| 9 | +// See CONTRIBUTORS.txt for the list of VS Code Swift project authors |
| 10 | +// |
| 11 | +// SPDX-License-Identifier: Apache-2.0 |
| 12 | +// |
| 13 | +//===----------------------------------------------------------------------===// |
| 14 | + |
| 15 | +import { makeDebugConfigurations } from "../debugger/launch"; |
| 16 | +import { FolderContext } from "../FolderContext"; |
| 17 | +import { WorkspaceContext } from "../WorkspaceContext"; |
| 18 | +import * as vscode from "vscode"; |
| 19 | + |
| 20 | +export async function generateLaunchConfigurations(ctx: WorkspaceContext): Promise<boolean> { |
| 21 | + if (ctx.folders.length === 0) { |
| 22 | + return false; |
| 23 | + } |
| 24 | + |
| 25 | + if (ctx.folders.length === 1) { |
| 26 | + return await makeDebugConfigurations(ctx.folders[0], { force: true, yes: true }); |
| 27 | + } |
| 28 | + |
| 29 | + const quickPickItems: SelectFolderQuickPick[] = ctx.folders.map(folder => ({ |
| 30 | + type: "folder", |
| 31 | + folder, |
| 32 | + label: folder.name, |
| 33 | + detail: folder.workspaceFolder.uri.fsPath, |
| 34 | + })); |
| 35 | + quickPickItems.push({ type: "all", label: "Generate For All Folders" }); |
| 36 | + const selection = await vscode.window.showQuickPick(quickPickItems, { |
| 37 | + matchOnDetail: true, |
| 38 | + placeHolder: "Select a folder to generate launch configurations for", |
| 39 | + }); |
| 40 | + |
| 41 | + if (!selection) { |
| 42 | + return false; |
| 43 | + } |
| 44 | + |
| 45 | + const foldersToUpdate: FolderContext[] = []; |
| 46 | + if (selection.type === "all") { |
| 47 | + foldersToUpdate.push(...ctx.folders); |
| 48 | + } else { |
| 49 | + foldersToUpdate.push(selection.folder); |
| 50 | + } |
| 51 | + |
| 52 | + return ( |
| 53 | + await Promise.all( |
| 54 | + foldersToUpdate.map(folder => |
| 55 | + makeDebugConfigurations(folder, { force: true, yes: true }) |
| 56 | + ) |
| 57 | + ) |
| 58 | + ).reduceRight((prev, curr) => prev || curr); |
| 59 | +} |
| 60 | + |
| 61 | +type SelectFolderQuickPick = AllQuickPickItem | FolderQuickPickItem; |
| 62 | + |
| 63 | +interface AllQuickPickItem extends vscode.QuickPickItem { |
| 64 | + type: "all"; |
| 65 | +} |
| 66 | + |
| 67 | +interface FolderQuickPickItem extends vscode.QuickPickItem { |
| 68 | + type: "folder"; |
| 69 | + folder: FolderContext; |
| 70 | +} |
0 commit comments