@@ -15,16 +15,17 @@ import * as path from "path";
1515import * as vscode from "vscode" ;
1616
1717import { SwiftLogger } from "../logging/SwiftLogger" ;
18- import { Swiftly } from "../toolchain/swiftly" ;
18+ import { Swiftly , SwiftlyFactory } from "../toolchain/swiftly" ;
1919import { Workbench } from "../utilities/commands" ;
2020import { installSwiftlyToolchainWithProgress } from "./installSwiftlyToolchain" ;
2121
2222/**
23- * Prompts user for Swiftly installation with directory customization options
24- * @param logger Optional logger
25- * @returns A promise that resolves to true if the user has opted to install swiftly, false otherwise
23+ * Prompts user for Swiftly installation with directory customization options.
24+ *
25+ * @param logger The logger to use for logging messages.
26+ * @returns A promise that resolves to `true` if the user has opted to install swiftly, `false` otherwise.
2627 */
27- export async function promptForSwiftlyInstallation ( logger ? : SwiftLogger ) : Promise < boolean > {
28+ export async function promptForSwiftlyInstallation ( logger : SwiftLogger ) : Promise < boolean > {
2829 const installMessage = `A .swift-version file was detected. Install Swiftly to automatically manage Swift toolchain versions for this project.` ;
2930
3031 const selection = await vscode . window . showWarningMessage (
@@ -66,19 +67,19 @@ This process involves updating your shell profile in order to add swiftly to you
6667 await vscode . workspace
6768 . getConfiguration ( "swift" )
6869 . update ( "disableSwiftlyInstallPrompt" , true , vscode . ConfigurationTarget . Global ) ;
69- logger ? .info ( "Swiftly installation prompt suppressed by user" ) ;
70+ logger . info ( "Swiftly installation prompt suppressed by user" ) ;
7071 }
7172
7273 return false ;
7374}
7475
7576/**
76- * Installs Swiftly with progress tracking and user feedback
77- * @param options Installation options
78- * @param logger Optional logger
79- * @returns Promise<boolean> true if installation succeeded
77+ * Installs Swiftly with progress tracking and user feedback.
78+ *
79+ * @param logger The logger to use for logging messages.
80+ * @returns A promise that resolves to ` true` if installation succeeded, `false` otherwise.
8081 */
81- export async function installSwiftlyWithProgress ( logger ? : SwiftLogger ) : Promise < boolean > {
82+ export async function installSwiftlyWithProgress ( logger : SwiftLogger ) : Promise < boolean > {
8283 try {
8384 await vscode . window . withProgress (
8485 {
@@ -92,14 +93,14 @@ export async function installSwiftlyWithProgress(logger?: SwiftLogger): Promise<
9293 ) ;
9394 return true ;
9495 } catch ( error ) {
95- logger ? .error ( `Failed to install Swiftly: ${ error } ` ) ;
96+ logger . error ( `Failed to install Swiftly: ${ error } ` ) ;
9697 const message = error instanceof Error ? error . message : String ( error ) ;
9798 void vscode . window . showErrorMessage ( `Failed to install Swiftly: ${ message } ` ) ;
9899 return false ;
99100 }
100101}
101102
102- async function promptToRestartVSCode ( ) : Promise < void > {
103+ async function promptToRestartVSCode ( ) : Promise < boolean > {
103104 const selection = await vscode . window . showInformationMessage (
104105 "Restart VS Code" ,
105106 {
@@ -110,27 +111,34 @@ async function promptToRestartVSCode(): Promise<void> {
110111 ) ;
111112 if ( selection === "Quit Visual Studio Code" ) {
112113 await vscode . commands . executeCommand ( Workbench . ACTION_QUIT ) ;
114+ return true ;
113115 }
116+ return false ;
114117}
115118
116119/**
117- * Main function to handle missing Swiftly detection and installation
118- * @param swiftVersionFiles A list of swift version files that will need to be installed
119- * @param logger Optional logger
120- * @returns Promise<boolean> true if Swiftly was installed or already exists
120+ * Main function to handle missing Swiftly detection and installation.
121+ *
122+ * Asks the user whether or not they want to install Swiftly to manage their Swift toolchains. It will
123+ * also install the provided Swift toolchain versions after installing Swiftly.
124+ *
125+ * @param swiftlyFactory Factory used to create a Swiftly instance after installation.
126+ * @param swiftVersions An array of Swift toolchain versions to install.
127+ * @param logger The logger to use for logging messages.
128+ * @returns A promise that resolves to `true` if Swiftly was installed or already exists, `false` otherwise.
121129 */
122130export async function handleMissingSwiftly (
131+ swiftlyFactory : SwiftlyFactory ,
123132 swiftVersions : string [ ] ,
124- extensionRoot : string ,
125- logger ?: SwiftLogger
133+ logger : SwiftLogger
126134) : Promise < boolean > {
127135 if ( await Swiftly . isInstalled ( ) ) {
128136 return true ;
129137 }
130138
131139 // Check if the user wants to disable the prompt
132140 if ( vscode . workspace . getConfiguration ( "swift" ) . get ( "disableSwiftlyInstallPrompt" , false ) ) {
133- logger ? .debug ( "Swiftly installation prompt is suppressed" ) ;
141+ logger . debug ( "Swiftly installation prompt is suppressed" ) ;
134142 return false ;
135143 }
136144
@@ -145,12 +153,11 @@ export async function handleMissingSwiftly(
145153 }
146154
147155 // Install toolchains
148- const swiftlyPath = path . join ( Swiftly . defaultHomeDir ( ) , "bin/swiftly" ) ;
156+ const swiftly = swiftlyFactory . create ( path . join ( Swiftly . defaultHomeDir ( ) , "bin/swiftly" ) ) ;
149157 for ( const version of swiftVersions ) {
150- await installSwiftlyToolchainWithProgress ( version , extensionRoot , logger , swiftlyPath ) ;
158+ await installSwiftlyToolchainWithProgress ( swiftly , version ) ;
151159 }
152160
153161 // VS Code needs to be restarted after installing swiftly
154- await promptToRestartVSCode ( ) ;
155- return true ;
162+ return await promptToRestartVSCode ( ) ;
156163}
0 commit comments