@@ -54,44 +54,61 @@ export class Swiftly {
54
54
* @returns the version of Swiftly as a `Version` object, or `undefined`
55
55
* if Swiftly is not installed or not supported.
56
56
*/
57
- public static async version ( ) : Promise < Version | undefined > {
57
+ public static async version (
58
+ outputChannel ?: vscode . OutputChannel
59
+ ) : Promise < Version | undefined > {
58
60
if ( ! Swiftly . isSupported ( ) ) {
59
61
return undefined ;
60
62
}
61
- const { stdout } = await execFile ( "swiftly" , [ "--version" ] ) ;
62
- return Version . fromString ( stdout . trim ( ) ) ;
63
+ try {
64
+ const { stdout } = await execFile ( "swiftly" , [ "--version" ] ) ;
65
+ return Version . fromString ( stdout . trim ( ) ) ;
66
+ } catch ( error ) {
67
+ outputChannel ?. appendLine ( `Failed to retrieve Swiftly version: ${ error } ` ) ;
68
+ return undefined ;
69
+ }
63
70
}
64
71
65
72
/**
66
73
* Finds the list of toolchains managed by Swiftly.
67
74
*
68
75
* @returns an array of toolchain paths
69
76
*/
70
- public static async listAvailableToolchains ( ) : Promise < string [ ] > {
77
+ public static async listAvailableToolchains (
78
+ outputChannel ?: vscode . OutputChannel
79
+ ) : Promise < string [ ] > {
71
80
if ( ! this . isSupported ( ) ) {
72
81
return [ ] ;
73
82
}
74
- const version = await Swiftly . version ( ) ;
75
- if ( version ?. isLessThan ( new Version ( 1 , 1 , 0 ) ) ) {
76
- return await Swiftly . getToolchainInstallLegacy ( ) ;
83
+ const version = await Swiftly . version ( outputChannel ) ;
84
+ if ( ! version ) {
85
+ outputChannel ?. appendLine ( "Swiftly is not installed" ) ;
86
+ return [ ] ;
87
+ }
88
+
89
+ if ( version . isLessThan ( new Version ( 1 , 1 , 0 ) ) ) {
90
+ return await Swiftly . getToolchainInstallLegacy ( outputChannel ) ;
77
91
}
78
92
79
- return await Swiftly . getListAvailableToolchains ( ) ;
93
+ return await Swiftly . getListAvailableToolchains ( outputChannel ) ;
80
94
}
81
95
82
- private static async getListAvailableToolchains ( ) : Promise < string [ ] > {
96
+ private static async getListAvailableToolchains (
97
+ outputChannel ?: vscode . OutputChannel
98
+ ) : Promise < string [ ] > {
83
99
try {
84
100
const { stdout } = await execFile ( "swiftly" , [ "list-available" , "--format=json" ] ) ;
85
101
const response = ListAvailableResult . parse ( JSON . parse ( stdout ) ) ;
86
102
return response . toolchains . map ( t => t . name ) ;
87
103
} catch ( error ) {
104
+ outputChannel ?. appendLine ( `Failed to retrieve Swiftly installations: ${ error } ` ) ;
88
105
throw new Error (
89
106
`Failed to retrieve Swiftly installations from disk: ${ ( error as Error ) . message } `
90
107
) ;
91
108
}
92
109
}
93
110
94
- private static async getToolchainInstallLegacy ( ) {
111
+ private static async getToolchainInstallLegacy ( outputChannel ?: vscode . OutputChannel ) {
95
112
try {
96
113
const swiftlyHomeDir : string | undefined = process . env [ "SWIFTLY_HOME_DIR" ] ;
97
114
if ( ! swiftlyHomeDir ) {
@@ -109,6 +126,7 @@ export class Swiftly {
109
126
. filter ( ( toolchain ) : toolchain is string => typeof toolchain === "string" )
110
127
. map ( toolchain => path . join ( swiftlyHomeDir , "toolchains" , toolchain ) ) ;
111
128
} catch ( error ) {
129
+ outputChannel ?. appendLine ( `Failed to retrieve Swiftly installations: ${ error } ` ) ;
112
130
throw new Error (
113
131
`Failed to retrieve Swiftly installations from disk: ${ ( error as Error ) . message } `
114
132
) ;
@@ -131,7 +149,10 @@ export class Swiftly {
131
149
* the path to the active toolchain.
132
150
* @returns The location of the active toolchain if swiftly is being used to manage it.
133
151
*/
134
- public static async toolchain ( cwd ?: vscode . Uri ) : Promise < string | undefined > {
152
+ public static async toolchain (
153
+ outputChannel ?: vscode . OutputChannel ,
154
+ cwd ?: vscode . Uri
155
+ ) : Promise < string | undefined > {
135
156
const swiftlyHomeDir : string | undefined = process . env [ "SWIFTLY_HOME_DIR" ] ;
136
157
if ( swiftlyHomeDir ) {
137
158
const { stdout : swiftLocation } = await execFile ( "which" , [ "swift" ] ) ;
@@ -145,6 +166,7 @@ export class Swiftly {
145
166
return path . join ( inUse , "usr" ) ;
146
167
}
147
168
} catch ( err : unknown ) {
169
+ outputChannel ?. appendLine ( `Failed to retrieve Swiftly installations: ${ err } ` ) ;
148
170
const error = err as ExecFileError ;
149
171
// Its possible the toolchain in .swift-version is misconfigured or doesn't exist.
150
172
void vscode . window . showErrorMessage (
0 commit comments