@@ -20,6 +20,7 @@ import configuration from "../configuration";
2020import { SwiftLogger } from "../logging/SwiftLogger" ;
2121import { Swiftly } from "../toolchain/swiftly" ;
2222import { SwiftToolchain } from "../toolchain/toolchain" ;
23+ import { isEmptyObject } from "../utilities/utilities" ;
2324import { showReloadExtensionNotification } from "./ReloadExtension" ;
2425
2526/**
@@ -406,50 +407,48 @@ export async function showToolchainSelectionQuickPick(
406407 if ( selectedToolchain ?. type === "toolchain" ) {
407408 // Select an Xcode to build with
408409 let developerDir : string | undefined = undefined ;
409- if ( process . platform === "darwin" ) {
410- let selectedXcodePath : string | undefined = undefined ;
411- if ( selectedToolchain . category === "xcode" ) {
412- selectedXcodePath = selectedToolchain . xcodePath ;
413- } else if ( xcodePaths . length === 1 ) {
414- selectedXcodePath = xcodePaths [ 0 ] ;
415- } else if ( xcodePaths . length > 1 ) {
416- selectedXcodePath = await showDeveloperDirQuickPick ( xcodePaths ) ;
417- if ( ! selectedXcodePath ) {
418- return ;
419- }
420- }
421- // Find the actual DEVELOPER_DIR based on the selected Xcode app
422- if ( selectedXcodePath ) {
423- developerDir = await SwiftToolchain . getXcodeDeveloperDir ( {
424- ...process . env ,
425- DEVELOPER_DIR : selectedXcodePath ,
426- } ) ;
410+ if ( selectedToolchain . category === "xcode" ) {
411+ developerDir = await SwiftToolchain . getXcodeDeveloperDir ( {
412+ ...process . env ,
413+ DEVELOPER_DIR : selectedToolchain . xcodePath ,
414+ } ) ;
415+ } else {
416+ const selectedDeveloperDir = await showDeveloperDirQuickPick ( xcodePaths ) ;
417+ if ( ! selectedDeveloperDir ) {
418+ return ;
427419 }
420+ developerDir = selectedDeveloperDir . developerDir ;
428421 }
429422 // Update the toolchain configuration
430423 await setToolchainPath ( selectedToolchain , developerDir ) ;
431424 return ;
432425 }
433426}
434427
435- /**
436- * Prompt the user to choose a value for the DEVELOPER_DIR environment variable.
437- *
438- * @param xcodePaths An array of paths to available Xcode installations on the system
439- * @returns The selected DEVELOPER_DIR or undefined if the user cancelled selection
440- */
441- export async function showDeveloperDirQuickPick ( xcodePaths : string [ ] ) : Promise < string | undefined > {
442- const selected = await vscode . window . showQuickPick < vscode . QuickPickItem > (
428+ async function showXcodeQuickPick (
429+ xcodePaths : string [ ]
430+ ) : Promise < { type : "selected" ; xcodePath : string | undefined } | undefined > {
431+ if ( process . platform !== "darwin" || xcodePaths . length === 0 ) {
432+ return { type : "selected" , xcodePath : undefined } ;
433+ }
434+ if ( xcodePaths . length === 1 ) {
435+ return { type : "selected" , xcodePath : xcodePaths [ 1 ] } ;
436+ }
437+ type XcodeQuickPickItem = vscode . QuickPickItem & { inUse : boolean ; xcodePath : string } ;
438+ const selected = await vscode . window . showQuickPick < XcodeQuickPickItem > (
443439 SwiftToolchain . getXcodeDeveloperDir ( configuration . swiftEnvironmentVariables ) . then (
444440 existingDeveloperDir => {
445441 return xcodePaths
446442 . map ( xcodePath => {
447- const result : vscode . QuickPickItem = {
443+ const result : XcodeQuickPickItem = {
448444 label : path . basename ( xcodePath , ".app" ) ,
449445 detail : xcodePath ,
446+ inUse : false ,
447+ xcodePath,
450448 } ;
451449 if ( existingDeveloperDir . startsWith ( xcodePath ) ) {
452450 result . description = "$(check) in use" ;
451+ result . inUse = true ;
453452 }
454453 return result ;
455454 } )
@@ -472,7 +471,35 @@ export async function showDeveloperDirQuickPick(xcodePaths: string[]): Promise<s
472471 canPickMany : false ,
473472 }
474473 ) ;
475- return selected ?. detail ;
474+ if ( ! selected ) {
475+ return undefined ;
476+ }
477+ return { type : "selected" , xcodePath : selected . xcodePath } ;
478+ }
479+
480+ /**
481+ * Prompt the user to choose a value for the DEVELOPER_DIR environment variable.
482+ *
483+ * @param xcodePaths An array of paths to available Xcode installations on the system
484+ * @returns The selected DEVELOPER_DIR or undefined if the user cancelled selection
485+ */
486+ export async function showDeveloperDirQuickPick (
487+ xcodePaths : string [ ]
488+ ) : Promise < { developerDir : string | undefined } | undefined > {
489+ const selectedXcode = await showXcodeQuickPick ( xcodePaths ) ;
490+ if ( ! selectedXcode ) {
491+ return undefined ;
492+ }
493+ if ( ! selectedXcode . xcodePath ) {
494+ return { developerDir : undefined } ;
495+ }
496+ // Find the actual DEVELOPER_DIR based on the selected Xcode app
497+ return {
498+ developerDir : await SwiftToolchain . getXcodeDeveloperDir ( {
499+ ...process . env ,
500+ DEVELOPER_DIR : selectedXcode . xcodePath ,
501+ } ) ,
502+ } ;
476503}
477504
478505/**
@@ -554,13 +581,13 @@ export async function setToolchainPath(
554581 const toolchainPath = toolchain . category !== "swiftly" ? toolchain . swiftFolderPath : undefined ;
555582 const swiftConfiguration = vscode . workspace . getConfiguration ( "swift" ) ;
556583 await swiftConfiguration . update ( "path" , toolchainPath , target ) ;
557- const swiftEnv = configuration . swiftEnvironmentVariables ;
584+ const swiftEnvironmentVariables = {
585+ ...configuration . swiftEnvironmentVariables ,
586+ DEVELOPER_DIR : developerDir ,
587+ } ;
558588 await swiftConfiguration . update (
559589 "swiftEnvironmentVariables" ,
560- {
561- ...swiftEnv ,
562- DEVELOPER_DIR : developerDir ,
563- } ,
590+ isEmptyObject ( swiftEnvironmentVariables ) ? undefined : swiftEnvironmentVariables ,
564591 target
565592 ) ;
566593 await checkAndRemoveWorkspaceSetting ( target ) ;
0 commit comments