Skip to content

Commit 09f00ee

Browse files
hide Swiftly install commands from the toolchain selection quick pick when Swiftly doesn't support it
1 parent 4c83ddf commit 09f00ee

File tree

1 file changed

+52
-40
lines changed

1 file changed

+52
-40
lines changed

src/ui/ToolchainSelection.ts

Lines changed: 52 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -271,60 +271,72 @@ async function getQuickPickItems(
271271
}
272272
}
273273
// Various actions that the user can perform (e.g. to install new toolchains)
274-
const actionItems: ActionItem[] = [];
275-
if (Swiftly.isSupported() && !(await Swiftly.isInstalled())) {
276-
const platformName = process.platform === "linux" ? "Linux" : "macOS";
277-
actionItems.push({
274+
const actionItems: ActionItem[] = [
275+
...(await getSwiftlyActions()),
276+
{
278277
type: "action",
279-
label: "$(swift-icon) Install Swiftly for toolchain management...",
280-
detail: `Install https://swiftlang.github.io/swiftly to manage your toolchains on ${platformName}`,
281-
run: installSwiftly,
282-
});
283-
}
278+
label: "$(cloud-download) Download from Swift.org...",
279+
detail: "Open https://swift.org/install to download and install a toolchain",
280+
run: downloadToolchain,
281+
},
282+
{
283+
type: "action",
284+
label: "$(folder-opened) Select toolchain directory...",
285+
detail: "Select a folder on your machine where the Swift toolchain is installed",
286+
run: selectToolchainFolder,
287+
},
288+
];
284289

285-
// Add install Swiftly toolchain actions if Swiftly is installed
286-
if (Swiftly.isSupported() && (await Swiftly.isInstalled())) {
287-
actionItems.push({
290+
return [
291+
...(swiftlyToolchains.length > 0
292+
? [new SeparatorItem("swiftly"), ...swiftlyToolchains]
293+
: []),
294+
...(xcodes.length > 0 ? [new SeparatorItem("Xcode"), ...xcodes] : []),
295+
...(sortedToolchains.length > 0
296+
? [new SeparatorItem("toolchains"), ...sortedToolchains]
297+
: []),
298+
new SeparatorItem("actions"),
299+
...actionItems,
300+
];
301+
}
302+
303+
async function getSwiftlyActions(): Promise<ActionItem[]> {
304+
if (!Swiftly.isSupported()) {
305+
return [];
306+
}
307+
if (!(await Swiftly.isInstalled())) {
308+
const platformName = process.platform === "linux" ? "Linux" : "macOS";
309+
return [
310+
{
311+
type: "action",
312+
label: "$(swift-icon) Install Swiftly for toolchain management...",
313+
detail: `Install https://swiftlang.github.io/swiftly to manage your toolchains on ${platformName}`,
314+
run: installSwiftly,
315+
},
316+
];
317+
}
318+
// We only support installing toolchains via Swiftly starting in Swiftly 1.1.0
319+
const swiftlyVersion = await Swiftly.version();
320+
if (swiftlyVersion?.isLessThan({ major: 1, minor: 1, patch: 0 })) {
321+
return [];
322+
}
323+
return [
324+
{
288325
type: "action",
289326
label: "$(cloud-download) Install Swiftly toolchain...",
290327
detail: "Install a Swift stable release toolchain via Swiftly",
291328
run: async () => {
292329
await vscode.commands.executeCommand(Commands.INSTALL_SWIFTLY_TOOLCHAIN);
293330
},
294-
});
295-
296-
actionItems.push({
331+
},
332+
{
297333
type: "action",
298334
label: "$(beaker) Install Swiftly snapshot toolchain...",
299335
detail: "Install a Swift snapshot toolchain via Swiftly from development builds",
300336
run: async () => {
301337
await vscode.commands.executeCommand(Commands.INSTALL_SWIFTLY_SNAPSHOT_TOOLCHAIN);
302338
},
303-
});
304-
}
305-
306-
actionItems.push({
307-
type: "action",
308-
label: "$(cloud-download) Download from Swift.org...",
309-
detail: "Open https://swift.org/install to download and install a toolchain",
310-
run: downloadToolchain,
311-
});
312-
actionItems.push({
313-
type: "action",
314-
label: "$(folder-opened) Select toolchain directory...",
315-
detail: "Select a folder on your machine where the Swift toolchain is installed",
316-
run: selectToolchainFolder,
317-
});
318-
return [
319-
...(swiftlyToolchains.length > 0
320-
? [new SeparatorItem("swiftly"), ...swiftlyToolchains]
321-
: []),
322-
...(xcodes.length > 0 ? [new SeparatorItem("Xcode"), ...xcodes] : []),
323-
...(sortedToolchains.length > 0
324-
? [new SeparatorItem("toolchains"), ...sortedToolchains]
325-
: []),
326-
new SeparatorItem("actions"),
327-
...actionItems,
339+
},
328340
];
329341
}
330342

0 commit comments

Comments
 (0)