Skip to content

Fixed JSON parsing error while selecting toolchain #1743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 25, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions src/toolchain/swiftly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,25 @@ import * as vscode from "vscode";
import { Version } from "../utilities/version";
import { z } from "zod";

const ListAvailableResult = z.object({
const ListResult = z.object({
toolchains: z.array(
z.object({
inUse: z.boolean(),
installed: z.boolean(),
isDefault: z.boolean(),
name: z.string(),
version: z.discriminatedUnion("type", [
z.object({
major: z.number(),
minor: z.number(),
patch: z.number().optional(),
name: z.string(),
type: z.literal("stable"),
}),
z.object({
major: z.number(),
minor: z.number(),
branch: z.string(),
date: z.string(),

name: z.string(),
type: z.literal("snapshot"),
}),
]),
Expand Down Expand Up @@ -97,9 +96,9 @@ export class Swiftly {
outputChannel?: vscode.OutputChannel
): Promise<string[]> {
try {
const { stdout } = await execFile("swiftly", ["list-available", "--format=json"]);
const response = ListAvailableResult.parse(JSON.parse(stdout));
return response.toolchains.map(t => t.name);
const { stdout } = await execFile("swiftly", ["list", "--format=json"]);
const response = ListResult.parse(JSON.parse(stdout));
return response.toolchains.map(t => t.version.name);
} catch (error) {
outputChannel?.appendLine(`Failed to retrieve Swiftly installations: ${error}`);
throw new Error(
Expand Down