File tree Expand file tree Collapse file tree 3 files changed +32
-17
lines changed
test/unit-tests/toolchain Expand file tree Collapse file tree 3 files changed +32
-17
lines changed Original file line number Diff line number Diff line change @@ -101,9 +101,7 @@ export class Swiftly {
101
101
return response . toolchains . map ( t => t . version . name ) ;
102
102
} catch ( error ) {
103
103
outputChannel ?. appendLine ( `Failed to retrieve Swiftly installations: ${ error } ` ) ;
104
- throw new Error (
105
- `Failed to retrieve Swiftly installations from disk: ${ ( error as Error ) . message } `
106
- ) ;
104
+ return [ ] ;
107
105
}
108
106
}
109
107
@@ -143,6 +141,13 @@ export class Swiftly {
143
141
return inUse . trimEnd ( ) ;
144
142
}
145
143
144
+ public static async use ( version : string ) : Promise < void > {
145
+ if ( ! this . isSupported ( ) ) {
146
+ throw new Error ( "Swiftly is not supported on this platform" ) ;
147
+ }
148
+ await execFile ( "swiftly" , [ "use" , version ] ) ;
149
+ }
150
+
146
151
/**
147
152
* Determine if Swiftly is being used to manage the active toolchain and if so, return
148
153
* the path to the active toolchain.
Original file line number Diff line number Diff line change @@ -304,7 +304,22 @@ export async function showToolchainSelectionQuickPick(activeToolchain: SwiftTool
304
304
}
305
305
}
306
306
// Update the toolchain path
307
- const isUpdated = await setToolchainPath ( selected . swiftFolderPath , developerDir ) ;
307
+ let swiftPath = selected . swiftFolderPath ;
308
+
309
+ // Handle Swiftly toolchains specially
310
+ if ( selected . category === "swiftly" ) {
311
+ try {
312
+ // Run swiftly use <version> and get the path to the toolchain
313
+ await Swiftly . use ( selected . label ) ;
314
+ const inUseLocation = await Swiftly . inUseLocation ( "swiftly" ) ;
315
+ swiftPath = path . join ( inUseLocation , "usr" , "bin" ) ;
316
+ } catch ( error ) {
317
+ void vscode . window . showErrorMessage ( `Failed to switch Swiftly toolchain: ${ error } ` ) ;
318
+ return ;
319
+ }
320
+ }
321
+
322
+ const isUpdated = await setToolchainPath ( swiftPath , developerDir ) ;
308
323
if ( isUpdated && selected . onDidSelect ) {
309
324
await selected . onDidSelect ( ) ;
310
325
}
Original file line number Diff line number Diff line change @@ -38,50 +38,45 @@ suite("Swiftly Unit Tests", () => {
38
38
toolchains : [
39
39
{
40
40
inUse : true ,
41
- installed : true ,
42
41
isDefault : true ,
43
- name : "swift-5.9.0-RELEASE" ,
44
42
version : {
45
43
major : 5 ,
46
44
minor : 9 ,
47
45
patch : 0 ,
46
+ name : "swift-5.9.0-RELEASE" ,
48
47
type : "stable" ,
49
48
} ,
50
49
} ,
51
50
{
52
51
inUse : false ,
53
- installed : true ,
54
52
isDefault : false ,
55
- name : "swift-5.8.0-RELEASE" ,
56
53
version : {
57
54
major : 5 ,
58
55
minor : 8 ,
59
56
patch : 0 ,
57
+ name : "swift-5.8.0-RELEASE" ,
60
58
type : "stable" ,
61
59
} ,
62
60
} ,
63
61
{
64
62
inUse : false ,
65
- installed : false ,
66
63
isDefault : false ,
67
- name : "swift-DEVELOPMENT-SNAPSHOT-2023-10-15-a" ,
68
64
version : {
69
65
major : 5 ,
70
66
minor : 10 ,
71
67
branch : "development" ,
72
68
date : "2023-10-15" ,
69
+ name : "swift-DEVELOPMENT-SNAPSHOT-2023-10-15-a" ,
73
70
type : "snapshot" ,
74
71
} ,
75
72
} ,
76
73
] ,
77
74
} ;
78
75
79
- mockUtilities . execFile
80
- . withArgs ( "swiftly" , [ "list-available" , "--format=json" ] )
81
- . resolves ( {
82
- stdout : JSON . stringify ( jsonOutput ) ,
83
- stderr : "" ,
84
- } ) ;
76
+ mockUtilities . execFile . withArgs ( "swiftly" , [ "list" , "--format=json" ] ) . resolves ( {
77
+ stdout : JSON . stringify ( jsonOutput ) ,
78
+ stderr : "" ,
79
+ } ) ;
85
80
86
81
const result = await Swiftly . listAvailableToolchains ( ) ;
87
82
@@ -93,7 +88,7 @@ suite("Swiftly Unit Tests", () => {
93
88
94
89
expect ( mockUtilities . execFile ) . to . have . been . calledWith ( "swiftly" , [ "--version" ] ) ;
95
90
expect ( mockUtilities . execFile ) . to . have . been . calledWith ( "swiftly" , [
96
- "list-available " ,
91
+ "list" ,
97
92
"--format=json" ,
98
93
] ) ;
99
94
} ) ;
You can’t perform that action at this time.
0 commit comments