@@ -271,60 +271,72 @@ async function getQuickPickItems(
271
271
}
272
272
}
273
273
// 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
+ {
278
277
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
+ ] ;
284
289
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
+ {
288
325
type : "action" ,
289
326
label : "$(cloud-download) Install Swiftly toolchain..." ,
290
327
detail : "Install a Swift stable release toolchain via Swiftly" ,
291
328
run : async ( ) => {
292
329
await vscode . commands . executeCommand ( Commands . INSTALL_SWIFTLY_TOOLCHAIN ) ;
293
330
} ,
294
- } ) ;
295
-
296
- actionItems . push ( {
331
+ } ,
332
+ {
297
333
type : "action" ,
298
334
label : "$(beaker) Install Swiftly snapshot toolchain..." ,
299
335
detail : "Install a Swift snapshot toolchain via Swiftly from development builds" ,
300
336
run : async ( ) => {
301
337
await vscode . commands . executeCommand ( Commands . INSTALL_SWIFTLY_SNAPSHOT_TOOLCHAIN ) ;
302
338
} ,
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
+ } ,
328
340
] ;
329
341
}
330
342
0 commit comments