@@ -98,6 +98,7 @@ interface SwiftToolchainItem extends vscode.QuickPickItem {
98
98
type : "toolchain" ;
99
99
toolchainPath : string ;
100
100
swiftFolderPath : string ;
101
+ onDidSelect ?( ) : Promise < void > ;
101
102
}
102
103
103
104
/** A {@link vscode.QuickPickItem} that performs an action for the user */
@@ -150,13 +151,24 @@ async function getQuickPickItems(
150
151
} ) ;
151
152
const toolchains = ( await SwiftToolchain . getToolchainInstalls ( ) )
152
153
. reverse ( )
153
- . map < SwiftToolchainItem > ( toolchainPath => ( {
154
- type : "toolchain" ,
155
- label : path . basename ( toolchainPath , ".xctoolchain" ) ,
156
- detail : toolchainPath ,
157
- toolchainPath : path . join ( toolchainPath , "usr" ) ,
158
- swiftFolderPath : path . join ( toolchainPath , "usr" , "bin" ) ,
159
- } ) ) ;
154
+ . map < SwiftToolchainItem > ( toolchainPath => {
155
+ const result : SwiftToolchainItem = {
156
+ type : "toolchain" ,
157
+ label : path . basename ( toolchainPath , ".xctoolchain" ) ,
158
+ detail : toolchainPath ,
159
+ toolchainPath : path . join ( toolchainPath , "usr" ) ,
160
+ swiftFolderPath : path . join ( toolchainPath , "usr" , "bin" ) ,
161
+ } ;
162
+ if ( result . label === "swift-latest" ) {
163
+ result . label = "Latest Installed Toolchain" ;
164
+ result . onDidSelect = async ( ) => {
165
+ vscode . window . showInformationMessage (
166
+ `The Swift extension is now configured to always use the most recently installed toolchain pointed at by the symbolic link "${ toolchainPath } ".`
167
+ ) ;
168
+ } ;
169
+ }
170
+ return result ;
171
+ } ) ;
160
172
const swiftlyToolchains = ( await SwiftToolchain . getSwiftlyToolchainInstalls ( ) )
161
173
. reverse ( )
162
174
. map < SwiftToolchainItem > ( toolchainPath => ( {
@@ -233,7 +245,10 @@ export async function showToolchainSelectionQuickPick(activeToolchain: SwiftTool
233
245
if ( selected ?. type === "action" ) {
234
246
await selected . run ( ) ;
235
247
} else if ( selected ?. type === "toolchain" ) {
236
- await setToolchainPath ( selected . swiftFolderPath , "prompt" ) ;
248
+ const isUpdated = await setToolchainPath ( selected . swiftFolderPath , "prompt" ) ;
249
+ if ( isUpdated && selected . onDidSelect ) {
250
+ await selected . onDidSelect ( ) ;
251
+ }
237
252
}
238
253
}
239
254
@@ -249,7 +264,7 @@ async function removeToolchainPath() {
249
264
async function setToolchainPath (
250
265
value : string | undefined ,
251
266
target ?: vscode . ConfigurationTarget | "prompt"
252
- ) : Promise < void > {
267
+ ) : Promise < boolean > {
253
268
if ( target === "prompt" ) {
254
269
const items : ( vscode . QuickPickItem & {
255
270
target ?: vscode . ConfigurationTarget ;
@@ -275,14 +290,19 @@ async function setToolchainPath(
275
290
canPickMany : false ,
276
291
} ) ;
277
292
if ( ! selected ) {
278
- return ;
293
+ return false ;
279
294
}
280
295
target = selected . target ;
281
296
} else {
282
297
target = vscode . ConfigurationTarget . Global ; // Global scope by default
283
298
}
284
299
}
285
300
await vscode . workspace . getConfiguration ( "swift" ) . update ( "path" , value , target ) ;
301
+ await checkAndRemoveWorkspaceSetting ( target ) ;
302
+ return true ;
303
+ }
304
+
305
+ async function checkAndRemoveWorkspaceSetting ( target : vscode . ConfigurationTarget | undefined ) {
286
306
// Check to see if the configuration would be overridden by workspace settings
287
307
if ( target !== vscode . ConfigurationTarget . Global ) {
288
308
return ;
0 commit comments