@@ -98,25 +98,27 @@ export async function selectToolchain() {
98
98
}
99
99
100
100
/** A {@link vscode.QuickPickItem} that contains the path to an installed Swift toolchain */
101
- type SwiftToolchainItem = PublicSwiftToolchainItem | XcodeToolchainItem ;
101
+ type SwiftToolchainItem = PublicSwiftToolchainItem | XcodeToolchainItem | SwiftlyToolchainItem ;
102
102
103
103
/** Common properties for a {@link vscode.QuickPickItem} that represents a Swift toolchain */
104
104
interface BaseSwiftToolchainItem extends vscode . QuickPickItem {
105
105
type : "toolchain" ;
106
- toolchainPath : string ;
107
- swiftFolderPath : string ;
108
106
onDidSelect ?( ) : Promise < void > ;
109
107
}
110
108
111
109
/** A {@link vscode.QuickPickItem} for a Swift toolchain that has been installed manually */
112
110
interface PublicSwiftToolchainItem extends BaseSwiftToolchainItem {
113
- category : "public" | "swiftly" ;
111
+ category : "public" ;
112
+ toolchainPath : string ;
113
+ swiftFolderPath : string ;
114
114
}
115
115
116
116
/** A {@link vscode.QuickPickItem} for a Swift toolchain provided by an installed Xcode application */
117
117
interface XcodeToolchainItem extends BaseSwiftToolchainItem {
118
118
category : "xcode" ;
119
119
xcodePath : string ;
120
+ toolchainPath : string ;
121
+ swiftFolderPath : string ;
120
122
}
121
123
122
124
/** A {@link vscode.QuickPickItem} that performs an action for the user */
@@ -125,6 +127,11 @@ interface ActionItem extends vscode.QuickPickItem {
125
127
run ( ) : Promise < void > ;
126
128
}
127
129
130
+ interface SwiftlyToolchainItem extends BaseSwiftToolchainItem {
131
+ category : "swiftly" ;
132
+ version : string ;
133
+ }
134
+
128
135
/** A {@link vscode.QuickPickItem} that separates items in the UI */
129
136
class SeparatorItem implements vscode . QuickPickItem {
130
137
readonly type = "separator" ;
@@ -178,7 +185,6 @@ async function getQuickPickItems(
178
185
type : "toolchain" ,
179
186
category : "public" ,
180
187
label : path . basename ( toolchainPath , ".xctoolchain" ) ,
181
- detail : toolchainPath ,
182
188
toolchainPath : path . join ( toolchainPath , "usr" ) ,
183
189
swiftFolderPath : path . join ( toolchainPath , "usr" , "bin" ) ,
184
190
} ;
@@ -195,18 +201,28 @@ async function getQuickPickItems(
195
201
// Find any Swift toolchains installed via Swiftly
196
202
const swiftlyToolchains = ( await Swiftly . listAvailableToolchains ( ) )
197
203
. reverse ( )
198
- . map < SwiftToolchainItem > ( toolchainPath => ( {
204
+ . map < SwiftlyToolchainItem > ( toolchainPath => ( {
199
205
type : "toolchain" ,
200
- category : "swiftly" ,
201
206
label : path . basename ( toolchainPath ) ,
202
- detail : toolchainPath ,
203
- toolchainPath : path . join ( toolchainPath , "usr" ) ,
204
- swiftFolderPath : path . join ( toolchainPath , "usr" , "bin" ) ,
207
+ category : "swiftly" ,
208
+ version : path . basename ( toolchainPath ) ,
205
209
} ) ) ;
206
210
// Mark which toolchain is being actively used
207
211
if ( activeToolchain ) {
208
212
const toolchainInUse = [ ...xcodes , ...toolchains , ...swiftlyToolchains ] . find ( toolchain => {
209
- return toolchain . toolchainPath === activeToolchain . toolchainPath ;
213
+ if ( activeToolchain . isSwiftlyManaged ) {
214
+ if ( toolchain . category !== "swiftly" ) {
215
+ return false ;
216
+ }
217
+
218
+ // For Swiftly toolchains, check if the label matches the active toolchain version
219
+ return toolchain . label === activeToolchain . swiftVersion . toString ( ) ;
220
+ }
221
+ // For non-Swiftly toolchains, check if the toolchain path matches
222
+ return (
223
+ ( toolchain as PublicSwiftToolchainItem | XcodeToolchainItem ) . toolchainPath ===
224
+ activeToolchain . toolchainPath
225
+ ) ;
210
226
} ) ;
211
227
if ( toolchainInUse ) {
212
228
toolchainInUse . description = "$(check) in use" ;
@@ -304,19 +320,21 @@ export async function showToolchainSelectionQuickPick(activeToolchain: SwiftTool
304
320
}
305
321
}
306
322
// Update the toolchain path
307
- let swiftPath = selected . swiftFolderPath ;
323
+ let swiftPath : string ;
308
324
309
325
// Handle Swiftly toolchains specially
310
326
if ( selected . category === "swiftly" ) {
311
327
try {
312
328
// Run swiftly use <version> and get the path to the toolchain
313
329
await Swiftly . use ( selected . label ) ;
314
- const inUseLocation = await Swiftly . inUseLocation ( "swiftly" ) ;
315
- swiftPath = path . join ( inUseLocation , "usr" , "bin" ) ;
330
+ swiftPath = Swiftly . getBinDir ( ) ;
316
331
} catch ( error ) {
317
332
void vscode . window . showErrorMessage ( `Failed to switch Swiftly toolchain: ${ error } ` ) ;
318
333
return ;
319
334
}
335
+ } else {
336
+ // For non-Swiftly toolchains, use the swiftFolderPath
337
+ swiftPath = ( selected as PublicSwiftToolchainItem | XcodeToolchainItem ) . swiftFolderPath ;
320
338
}
321
339
322
340
const isUpdated = await setToolchainPath ( swiftPath , developerDir ) ;
0 commit comments