-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathuseLocal.ts
79 lines (76 loc) · 2.3 KB
/
useLocal.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//===----------------------------------------------------------------------===//
//
// 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 { FolderOperation, WorkspaceContext } from "../../WorkspaceContext";
import { createSwiftTask } from "../../tasks/SwiftTaskProvider";
import { executeTaskWithUI } from "../utilities";
/**
* Use local version of package dependency
*
* equivalent of `swift package edit --path <localpath> identifier
* @param identifier Identifier for dependency
* @param ctx workspace context
*/
export async function useLocalDependency(
identifier: string,
ctx: WorkspaceContext,
dep: vscode.Uri | undefined
): Promise<boolean> {
const currentFolder = ctx.currentFolder;
if (!currentFolder) {
ctx.outputChannel.log("currentFolder is not set.");
return false;
}
let folder = dep;
if (!folder) {
const folders = await vscode.window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
defaultUri: currentFolder.folder,
openLabel: "Select",
title: "Select folder",
});
if (!folders) {
return false;
}
folder = folders[0];
}
const task = createSwiftTask(
ctx.toolchain.buildFlags.withAdditionalFlags([
"package",
"edit",
"--path",
folder.fsPath,
identifier,
]),
"Edit Package Dependency",
{
scope: currentFolder.workspaceFolder,
cwd: currentFolder.folder,
prefix: currentFolder.name,
},
ctx.toolchain
);
const success = await executeTaskWithUI(
task,
`Use local version of ${identifier}`,
currentFolder,
true
);
if (success) {
ctx.fireEvent(currentFolder, FolderOperation.resolvedUpdated);
}
return success;
}