Skip to content

Commit 413fb8c

Browse files
committed
Added changelog and outputchannel
1 parent 0048272 commit 413fb8c

File tree

3 files changed

+41
-14
lines changed

3 files changed

+41
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
### Added
66

7+
- Added Swiftly toolchain management support `.swift-version` files, and integration with the toolchain selection UI ([#1717](https://github.com/swiftlang/vscode-swift/pull/1717)
78
- Added code lenses to run suites/tests, configurable with the `swift.showTestCodeLenses` setting ([#1698](https://github.com/swiftlang/vscode-swift/pull/1698))
89

910
## 2.8.0 - 2025-07-14

src/toolchain/swiftly.ts

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,44 +54,61 @@ export class Swiftly {
5454
* @returns the version of Swiftly as a `Version` object, or `undefined`
5555
* if Swiftly is not installed or not supported.
5656
*/
57-
public static async version(): Promise<Version | undefined> {
57+
public static async version(
58+
outputChannel?: vscode.OutputChannel
59+
): Promise<Version | undefined> {
5860
if (!Swiftly.isSupported()) {
5961
return undefined;
6062
}
61-
const { stdout } = await execFile("swiftly", ["--version"]);
62-
return Version.fromString(stdout.trim());
63+
try {
64+
const { stdout } = await execFile("swiftly", ["--version"]);
65+
return Version.fromString(stdout.trim());
66+
} catch (error) {
67+
outputChannel?.appendLine(`Failed to retrieve Swiftly version: ${error}`);
68+
return undefined;
69+
}
6370
}
6471

6572
/**
6673
* Finds the list of toolchains managed by Swiftly.
6774
*
6875
* @returns an array of toolchain paths
6976
*/
70-
public static async listAvailableToolchains(): Promise<string[]> {
77+
public static async listAvailableToolchains(
78+
outputChannel?: vscode.OutputChannel
79+
): Promise<string[]> {
7180
if (!this.isSupported()) {
7281
return [];
7382
}
74-
const version = await Swiftly.version();
75-
if (version?.isLessThan(new Version(1, 1, 0))) {
76-
return await Swiftly.getToolchainInstallLegacy();
83+
const version = await Swiftly.version(outputChannel);
84+
if (!version) {
85+
outputChannel?.appendLine("Swiftly is not installed");
86+
return [];
87+
}
88+
89+
if (version.isLessThan(new Version(1, 1, 0))) {
90+
return await Swiftly.getToolchainInstallLegacy(outputChannel);
7791
}
7892

79-
return await Swiftly.getListAvailableToolchains();
93+
return await Swiftly.getListAvailableToolchains(outputChannel);
8094
}
8195

82-
private static async getListAvailableToolchains(): Promise<string[]> {
96+
private static async getListAvailableToolchains(
97+
outputChannel?: vscode.OutputChannel
98+
): Promise<string[]> {
8399
try {
84100
const { stdout } = await execFile("swiftly", ["list-available", "--format=json"]);
85101
const response = ListAvailableResult.parse(JSON.parse(stdout));
86102
return response.toolchains.map(t => t.name);
87103
} catch (error) {
104+
outputChannel?.appendLine(`Failed to retrieve Swiftly installations: ${error}`);
88105
throw new Error(
89106
`Failed to retrieve Swiftly installations from disk: ${(error as Error).message}`
90107
);
91108
}
92109
}
93110

94-
private static async getToolchainInstallLegacy() {
111+
private static async getToolchainInstallLegacy(outputChannel?: vscode.OutputChannel) {
95112
try {
96113
const swiftlyHomeDir: string | undefined = process.env["SWIFTLY_HOME_DIR"];
97114
if (!swiftlyHomeDir) {
@@ -109,6 +126,7 @@ export class Swiftly {
109126
.filter((toolchain): toolchain is string => typeof toolchain === "string")
110127
.map(toolchain => path.join(swiftlyHomeDir, "toolchains", toolchain));
111128
} catch (error) {
129+
outputChannel?.appendLine(`Failed to retrieve Swiftly installations: ${error}`);
112130
throw new Error(
113131
`Failed to retrieve Swiftly installations from disk: ${(error as Error).message}`
114132
);
@@ -131,7 +149,10 @@ export class Swiftly {
131149
* the path to the active toolchain.
132150
* @returns The location of the active toolchain if swiftly is being used to manage it.
133151
*/
134-
public static async toolchain(cwd?: vscode.Uri): Promise<string | undefined> {
152+
public static async toolchain(
153+
outputChannel?: vscode.OutputChannel,
154+
cwd?: vscode.Uri
155+
): Promise<string | undefined> {
135156
const swiftlyHomeDir: string | undefined = process.env["SWIFTLY_HOME_DIR"];
136157
if (swiftlyHomeDir) {
137158
const { stdout: swiftLocation } = await execFile("which", ["swift"]);
@@ -145,6 +166,7 @@ export class Swiftly {
145166
return path.join(inUse, "usr");
146167
}
147168
} catch (err: unknown) {
169+
outputChannel?.appendLine(`Failed to retrieve Swiftly installations: ${err}`);
148170
const error = err as ExecFileError;
149171
// Its possible the toolchain in .swift-version is misconfigured or doesn't exist.
150172
void vscode.window.showErrorMessage(

src/toolchain/toolchain.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export class SwiftToolchain {
122122
outputChannel?: vscode.OutputChannel
123123
): Promise<SwiftToolchain> {
124124
const swiftFolderPath = await this.getSwiftFolderPath(folder, outputChannel);
125-
const toolchainPath = await this.getToolchainPath(swiftFolderPath, folder);
125+
const toolchainPath = await this.getToolchainPath(swiftFolderPath, folder, outputChannel);
126126
const targetInfo = await this.getSwiftTargetInfo(
127127
this._getToolchainExecutable(toolchainPath, "swift")
128128
);
@@ -610,7 +610,11 @@ export class SwiftToolchain {
610610
/**
611611
* @returns path to Toolchain folder
612612
*/
613-
private static async getToolchainPath(swiftPath: string, cwd?: vscode.Uri): Promise<string> {
613+
private static async getToolchainPath(
614+
swiftPath: string,
615+
cwd?: vscode.Uri,
616+
channel?: vscode.OutputChannel
617+
): Promise<string> {
614618
try {
615619
switch (process.platform) {
616620
case "darwin": {
@@ -630,7 +634,7 @@ export class SwiftToolchain {
630634
return path.dirname(configuration.path);
631635
}
632636

633-
const swiftlyToolchainLocation = await Swiftly.toolchain(cwd);
637+
const swiftlyToolchainLocation = await Swiftly.toolchain(channel, cwd);
634638
if (swiftlyToolchainLocation) {
635639
return swiftlyToolchainLocation;
636640
}

0 commit comments

Comments
 (0)