forked from swiftlang/vscode-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswitchPlatform.ts
56 lines (54 loc) · 2.09 KB
/
switchPlatform.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
//===----------------------------------------------------------------------===//
//
// This source file is part of the VS Code Swift open source project
//
// Copyright (c) 2021-2024 the VS Code Swift project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
import * as vscode from "vscode";
import { DarwinCompatibleTarget, SwiftToolchain } from "../toolchain/toolchain";
import configuration from "../configuration";
/**
* Switches the target SDK to the platform selected in a QuickPick UI.
*/
export async function switchPlatform() {
const picked = await vscode.window.showQuickPick(
[
{ value: undefined, label: "macOS" },
{ value: DarwinCompatibleTarget.iOS, label: "iOS" },
{ value: DarwinCompatibleTarget.tvOS, label: "tvOS" },
{ value: DarwinCompatibleTarget.watchOS, label: "watchOS" },
{ value: DarwinCompatibleTarget.visionOS, label: "visionOS" },
],
{
placeHolder: "Select a new target",
}
);
if (picked) {
try {
const sdkForTarget = picked.value
? await SwiftToolchain.getSDKForTarget(picked.value)
: "";
if (sdkForTarget !== undefined) {
if (sdkForTarget !== "") {
configuration.sdk = sdkForTarget;
vscode.window.showWarningMessage(
`Selecting the ${picked.label} SDK will provide code editing support, but compiling with this SDK will have undefined results.`
);
} else {
configuration.sdk = undefined;
}
} else {
vscode.window.showErrorMessage("Unable to obtain requested SDK path");
}
} catch {
vscode.window.showErrorMessage("Unable to obtain requested SDK path");
}
}
}