Skip to content

Commit ebd020d

Browse files
committed
Select folders when ctx.currentFolder is not set
1 parent d4804a2 commit ebd020d

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

src/commands.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { runTask } from "./commands/runTask";
4646
import { TestKind } from "./TestExplorer/TestKind";
4747
import { pickProcess } from "./commands/pickProcess";
4848
import { openDocumentation } from "./commands/openDocumentation";
49+
import showFolderSelectionQuickPick from "./utilities/folderQuickPick";
4950

5051
/**
5152
* References:
@@ -147,10 +148,16 @@ export function register(ctx: WorkspaceContext): vscode.Disposable[] {
147148
vscode.commands.registerCommand(Commands.RUN_PLUGIN_TASK, () => runPluginTask()),
148149
vscode.commands.registerCommand(Commands.RUN_TASK, name => runTask(ctx, name)),
149150
vscode.commands.registerCommand("swift.restartLSPServer", async () => {
150-
if (!ctx.currentFolder) {
151+
const folder =
152+
ctx.currentFolder ??
153+
(await showFolderSelectionQuickPick(
154+
ctx,
155+
"Select a folder to restart the LSP server for"
156+
));
157+
if (!folder) {
151158
return;
152159
}
153-
const languageClientManager = ctx.languageClientManager.get(ctx.currentFolder);
160+
const languageClientManager = ctx.languageClientManager.get(folder);
154161
await languageClientManager.restart();
155162
}),
156163
vscode.commands.registerCommand("swift.reindexProject", () => reindexProject(ctx)),

src/commands/dependencies/resolve.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ import { FolderContext } from "../../FolderContext";
1717
import { createSwiftTask, SwiftTaskProvider } from "../../tasks/SwiftTaskProvider";
1818
import { WorkspaceContext } from "../../WorkspaceContext";
1919
import { executeTaskWithUI, updateAfterError } from "../utilities";
20+
import showFolderSelectionQuickPick from "../../utilities/folderQuickPick";
2021

2122
/**
2223
* Executes a {@link vscode.Task task} to resolve this package's dependencies.
2324
*/
2425
export async function resolveDependencies(ctx: WorkspaceContext) {
25-
const current = ctx.currentFolder;
26+
const current =
27+
ctx.currentFolder ??
28+
(await showFolderSelectionQuickPick(ctx, "Select a folder to resolve dependencies for"));
2629
if (!current) {
27-
ctx.outputChannel.log("currentFolder is not set.");
2830
return false;
2931
}
3032
return await resolveFolderDependencies(current);

src/utilities/folderQuickPick.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 * as vscode from "vscode";
16+
import { WorkspaceContext } from "../WorkspaceContext";
17+
import { FolderContext } from "../FolderContext";
18+
19+
export default async function showFolderSelectionQuickPick(
20+
ctx: WorkspaceContext,
21+
placeHolder: string = "Select a folder"
22+
): Promise<FolderContext | undefined> {
23+
const folders: vscode.QuickPickItem[] = ctx.folders.map(folder => ({
24+
label: folder.name,
25+
description: folder.folder.fsPath.toString(),
26+
}));
27+
const selected = await vscode.window.showQuickPick(folders, {
28+
title: "Toolchain Configuration",
29+
placeHolder: placeHolder,
30+
canPickMany: false,
31+
});
32+
33+
if (!selected) {
34+
return undefined;
35+
}
36+
37+
return ctx.folders.find(folder => folder.name === selected.label);
38+
}

0 commit comments

Comments
 (0)