@@ -167,11 +167,11 @@ export class Swiftly {
167
167
}
168
168
169
169
/**
170
- * Finds the list of toolchains managed by Swiftly.
170
+ * Finds the list of toolchains installed via Swiftly.
171
171
*
172
- * @returns an array of toolchain paths
172
+ * @returns an array of toolchain version names.
173
173
*/
174
- public static async listAvailableToolchains ( logger ?: SwiftLogger ) : Promise < string [ ] > {
174
+ public static async list ( logger ?: SwiftLogger ) : Promise < string [ ] > {
175
175
if ( ! this . isSupported ( ) ) {
176
176
return [ ] ;
177
177
}
@@ -182,13 +182,13 @@ export class Swiftly {
182
182
}
183
183
184
184
if ( ! ( await Swiftly . supportsJsonOutput ( logger ) ) ) {
185
- return await Swiftly . getToolchainInstallLegacy ( logger ) ;
185
+ return await Swiftly . listFromSwiftlyConfig ( logger ) ;
186
186
}
187
187
188
- return await Swiftly . getListAvailableToolchains ( logger ) ;
188
+ return await Swiftly . listUsingJSONFormat ( logger ) ;
189
189
}
190
190
191
- private static async getListAvailableToolchains ( logger ?: SwiftLogger ) : Promise < string [ ] > {
191
+ private static async listUsingJSONFormat ( logger ?: SwiftLogger ) : Promise < string [ ] > {
192
192
try {
193
193
const { stdout } = await execFile ( "swiftly" , [ "list" , "--format=json" ] ) ;
194
194
const response = ListResult . parse ( JSON . parse ( stdout ) ) ;
@@ -201,7 +201,7 @@ export class Swiftly {
201
201
}
202
202
}
203
203
204
- private static async getToolchainInstallLegacy ( logger ?: SwiftLogger ) {
204
+ private static async listFromSwiftlyConfig ( logger ?: SwiftLogger ) {
205
205
try {
206
206
const swiftlyHomeDir : string | undefined = process . env [ "SWIFTLY_HOME_DIR" ] ;
207
207
if ( ! swiftlyHomeDir ) {
@@ -226,17 +226,32 @@ export class Swiftly {
226
226
}
227
227
}
228
228
229
+ /**
230
+ * Checks whether or not the current operating system supports Swiftly.
231
+ */
229
232
public static isSupported ( ) {
230
233
return process . platform === "linux" || process . platform === "darwin" ;
231
234
}
232
235
236
+ /**
237
+ * Retrieves the location of the toolchain that is currently in use by Swiftly.
238
+ *
239
+ * @param swiftlyPath Optional path to the Swiftly binary.
240
+ * @param cwd Optional current working directory to check within.
241
+ */
233
242
public static async inUseLocation ( swiftlyPath : string = "swiftly" , cwd ?: vscode . Uri ) {
234
243
const { stdout : inUse } = await execFile ( swiftlyPath , [ "use" , "--print-location" ] , {
235
244
cwd : cwd ?. fsPath ,
236
245
} ) ;
237
246
return inUse . trimEnd ( ) ;
238
247
}
239
248
249
+ /**
250
+ * Retrieves the version name of the toolchain that is currently in use by Swiftly.
251
+ *
252
+ * @param swiftlyPath Optional path to the Swiftly binary.
253
+ * @param cwd Optional current working directory to check within.
254
+ */
240
255
public static async inUseVersion (
241
256
swiftlyPath : string = "swiftly" ,
242
257
cwd ?: vscode . Uri
@@ -256,6 +271,11 @@ export class Swiftly {
256
271
return result . version ;
257
272
}
258
273
274
+ /**
275
+ * Instructs Swiftly to use a specific version of the Swift toolchain.
276
+ *
277
+ * @param version The version name to use. Obtainable via {@link Swiftly.list}.
278
+ */
259
279
public static async use ( version : string ) : Promise < void > {
260
280
if ( ! this . isSupported ( ) ) {
261
281
throw new Error ( "Swiftly is not supported on this platform" ) ;
@@ -266,6 +286,7 @@ export class Swiftly {
266
286
/**
267
287
* Determine if Swiftly is being used to manage the active toolchain and if so, return
268
288
* the path to the active toolchain.
289
+ *
269
290
* @returns The location of the active toolchain if swiftly is being used to manage it.
270
291
*/
271
292
public static async toolchain (
@@ -298,15 +319,15 @@ export class Swiftly {
298
319
}
299
320
300
321
/**
301
- * Lists all toolchains available for installation from swiftly
322
+ * Lists all toolchains available for installation from swiftly.
302
323
*
303
- * @param branch Optional branch to filter available toolchains (e.g., "main" for snapshots)
304
- * @param logger Optional logger for error reporting
305
- * @returns Array of available toolchains
324
+ * @param branch Optional branch to filter available toolchains (e.g., "main" for snapshots).
325
+ * @param logger Optional logger for error reporting.
326
+ * @returns Array of available toolchains.
306
327
*/
307
328
public static async listAvailable (
308
- logger ?: SwiftLogger ,
309
- branch ?: string
329
+ branch ?: string ,
330
+ logger ?: SwiftLogger
310
331
) : Promise < SwiftlyToolchain [ ] > {
311
332
if ( ! this . isSupported ( ) ) {
312
333
return [ ] ;
@@ -340,11 +361,11 @@ export class Swiftly {
340
361
}
341
362
342
363
/**
343
- * Installs a toolchain via swiftly with optional progress tracking
364
+ * Installs a toolchain via swiftly with optional progress tracking.
344
365
*
345
- * @param version The toolchain version to install
346
- * @param progressCallback Optional callback that receives progress data as JSON objects
347
- * @param logger Optional logger for error reporting
366
+ * @param version The toolchain version to install.
367
+ * @param progressCallback Optional callback that receives progress data as JSON objects.
368
+ * @param logger Optional logger for error reporting.
348
369
*/
349
370
public static async installToolchain (
350
371
version : string ,
@@ -657,6 +678,9 @@ export class Swiftly {
657
678
return JSON . parse ( swiftlyConfigRaw ) ;
658
679
}
659
680
681
+ /**
682
+ * Checks whether or not Swiftly is installed on the current system.
683
+ */
660
684
public static async isInstalled ( ) : Promise < boolean > {
661
685
if ( ! this . isSupported ( ) ) {
662
686
return false ;
0 commit comments