1313//===----------------------------------------------------------------------===//
1414
1515import * as vscode from "vscode" ;
16- import { DarwinCompatibleTarget , getDarwinTargetTriple } from "../toolchain/toolchain" ;
16+ import { DarwinCompatibleTarget , SwiftToolchain } from "../toolchain/toolchain" ;
1717import configuration from "../configuration" ;
1818
1919/**
@@ -22,27 +22,35 @@ import configuration from "../configuration";
2222export async function switchPlatform ( ) {
2323 const picked = await vscode . window . showQuickPick (
2424 [
25- {
26- value : undefined ,
27- label : "macOS" ,
28- description : "default" ,
29- } ,
30- ...[
31- { value : DarwinCompatibleTarget . iOS , label : "iOS" } ,
32- { value : DarwinCompatibleTarget . tvOS , label : "tvOS" } ,
33- { value : DarwinCompatibleTarget . watchOS , label : "watchOS" } ,
34- { value : DarwinCompatibleTarget . visionOS , label : "visionOS" } ,
35- ] . map ( item => ( {
36- value : getDarwinTargetTriple ( item . value ) ,
37- description : getDarwinTargetTriple ( item . value ) ,
38- label : item . label ,
39- } ) ) ,
25+ { value : undefined , label : "macOS" } ,
26+ { value : DarwinCompatibleTarget . iOS , label : "iOS" } ,
27+ { value : DarwinCompatibleTarget . tvOS , label : "tvOS" } ,
28+ { value : DarwinCompatibleTarget . watchOS , label : "watchOS" } ,
29+ { value : DarwinCompatibleTarget . visionOS , label : "visionOS" } ,
4030 ] ,
4131 {
42- placeHolder : "Select a Swift SDK platform " ,
32+ placeHolder : "Select a new target " ,
4333 }
4434 ) ;
4535 if ( picked ) {
46- configuration . swiftSDK = picked . value ;
36+ try {
37+ const sdkForTarget = picked . value
38+ ? await SwiftToolchain . getSDKForTarget ( picked . value )
39+ : "" ;
40+ if ( sdkForTarget !== undefined ) {
41+ if ( sdkForTarget !== "" ) {
42+ configuration . sdk = sdkForTarget ;
43+ vscode . window . showWarningMessage (
44+ `Selecting the ${ picked . label } SDK will provide code editing support, but compiling with this SDK will have undefined results.`
45+ ) ;
46+ } else {
47+ configuration . sdk = undefined ;
48+ }
49+ } else {
50+ vscode . window . showErrorMessage ( "Unable to obtain requested SDK path" ) ;
51+ }
52+ } catch {
53+ vscode . window . showErrorMessage ( "Unable to obtain requested SDK path" ) ;
54+ }
4755 }
4856}
0 commit comments