@@ -118,8 +118,11 @@ export class SwiftToolchain {
118
118
this . swiftVersionString = targetInfo . compilerVersion ;
119
119
}
120
120
121
- static async create ( folder ?: vscode . Uri ) : Promise < SwiftToolchain > {
122
- const swiftFolderPath = await this . getSwiftFolderPath ( folder ) ;
121
+ static async create (
122
+ folder ?: vscode . Uri ,
123
+ outputChannel ?: vscode . OutputChannel
124
+ ) : Promise < SwiftToolchain > {
125
+ const swiftFolderPath = await this . getSwiftFolderPath ( folder , outputChannel ) ;
123
126
const toolchainPath = await this . getToolchainPath ( swiftFolderPath , folder ) ;
124
127
const targetInfo = await this . getSwiftTargetInfo (
125
128
this . _getToolchainExecutable ( toolchainPath , "swift" )
@@ -561,7 +564,10 @@ export class SwiftToolchain {
561
564
channel . logDiagnostic ( this . diagnostics ) ;
562
565
}
563
566
564
- private static async getSwiftFolderPath ( cwd ?: vscode . Uri ) : Promise < string > {
567
+ private static async getSwiftFolderPath (
568
+ cwd ?: vscode . Uri ,
569
+ outputChannel ?: vscode . OutputChannel
570
+ ) : Promise < string > {
565
571
try {
566
572
let swift : string ;
567
573
if ( configuration . path !== "" ) {
@@ -589,15 +595,17 @@ export class SwiftToolchain {
589
595
// use `type swift` to find `swift`. Run inside /bin/sh to ensure
590
596
// we get consistent output as different shells output a different
591
597
// format. Tried running with `-p` but that is not available in /bin/sh
592
- const { stdout } = await execFile ( "/bin/sh" , [
598
+ const { stdout, stderr } = await execFile ( "/bin/sh" , [
593
599
"-c" ,
594
600
"LC_MESSAGES=C type swift" ,
595
601
] ) ;
596
602
const swiftMatch = / ^ s w i f t i s ( .* ) $ / . exec ( stdout . trimEnd ( ) ) ;
597
603
if ( swiftMatch ) {
598
604
swift = swiftMatch [ 1 ] ;
599
605
} else {
600
- throw Error ( "Failed to find swift executable" ) ;
606
+ throw Error (
607
+ `/bin/sh -c LC_MESSAGES=C type swift: stdout: ${ stdout } , stderr: ${ stderr } `
608
+ ) ;
601
609
}
602
610
break ;
603
611
}
@@ -617,7 +625,8 @@ export class SwiftToolchain {
617
625
}
618
626
const swiftPath = expandFilePathTilde ( path . dirname ( realSwift ) ) ;
619
627
return await this . getSwiftEnvPath ( swiftPath ) ;
620
- } catch {
628
+ } catch ( error ) {
629
+ outputChannel ?. appendLine ( `Failed to find swift executable: ${ error } ` ) ;
621
630
throw Error ( "Failed to find swift executable" ) ;
622
631
}
623
632
}
0 commit comments