forked from swiftlang/vscode-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.ts
131 lines (126 loc) · 6.1 KB
/
commands.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//===----------------------------------------------------------------------===//
//
// 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 { WorkspaceContext } from "./WorkspaceContext";
import { PackageNode } from "./ui/PackageDependencyProvider";
import { SwiftToolchain } from "./toolchain/toolchain";
import { debugSnippet, runSnippet } from "./SwiftSnippets";
import { showToolchainSelectionQuickPick } from "./ui/ToolchainSelection";
import { captureDiagnostics } from "./commands/captureDiagnostics";
import { attachDebugger } from "./commands/attachDebugger";
import { reindexProject } from "./commands/reindexProject";
import { cleanBuild, debugBuild, runBuild } from "./commands/build";
import { runSwiftScript } from "./commands/runSwiftScript";
import { useLocalDependency } from "./commands/dependencies/useLocal";
import { editDependency } from "./commands/dependencies/edit";
import { uneditDependency } from "./commands/dependencies/unedit";
import { openInWorkspace } from "./commands/openInWorkspace";
import { openInExternalEditor } from "./commands/openInExternalEditor";
import { switchPlatform } from "./commands/switchPlatform";
import { insertFunctionComment } from "./commands/insertFunctionComment";
import { createNewProject } from "./commands/createNewProject";
import { openPackage } from "./commands/openPackage";
import { resolveDependencies } from "./commands/dependencies/resolve";
import { resetPackage } from "./commands/resetPackage";
import { updateDependencies } from "./commands/dependencies/update";
import { runPluginTask } from "./commands/runPluginTask";
import { runTestMultipleTimes } from "./commands/testMultipleTimes";
import { newSwiftFile } from "./commands/newFile";
/**
* References:
*
* - Contributing commands:
* https://code.visualstudio.com/api/references/contribution-points#contributes.commands
* - Implementing commands:
* https://code.visualstudio.com/api/extension-guides/command
*/
export type WorkspaceContextWithToolchain = WorkspaceContext & { toolchain: SwiftToolchain };
export function registerToolchainCommands(
toolchain: SwiftToolchain | undefined
): vscode.Disposable[] {
return [
vscode.commands.registerCommand("swift.createNewProject", () =>
createNewProject(toolchain)
),
vscode.commands.registerCommand("swift.selectToolchain", () =>
showToolchainSelectionQuickPick(toolchain)
),
];
}
/**
* Registers this extension's commands in the given {@link vscode.ExtensionContext context}.
*/
export function register(ctx: WorkspaceContext): vscode.Disposable[] {
return [
vscode.commands.registerCommand("swift.newFile", uri => newSwiftFile(uri)),
vscode.commands.registerCommand("swift.resolveDependencies", () =>
resolveDependencies(ctx)
),
vscode.commands.registerCommand("swift.updateDependencies", () => updateDependencies(ctx)),
vscode.commands.registerCommand("swift.run", () => runBuild(ctx)),
vscode.commands.registerCommand("swift.debug", () => debugBuild(ctx)),
vscode.commands.registerCommand("swift.cleanBuild", () => cleanBuild(ctx)),
vscode.commands.registerCommand("swift.runTestsMultipleTimes", item =>
runTestMultipleTimes(ctx, item, false)
),
vscode.commands.registerCommand("swift.runTestsUntilFailure", item =>
runTestMultipleTimes(ctx, item, true)
),
// Note: This is only available on macOS (gated in `package.json`) because its the only OS that has the iOS SDK available.
vscode.commands.registerCommand("swift.switchPlatform", () => switchPlatform()),
vscode.commands.registerCommand("swift.resetPackage", () => resetPackage(ctx)),
vscode.commands.registerCommand("swift.runScript", () => runSwiftScript(ctx)),
vscode.commands.registerCommand("swift.openPackage", () => openPackage(ctx)),
vscode.commands.registerCommand("swift.runSnippet", () => runSnippet(ctx)),
vscode.commands.registerCommand("swift.debugSnippet", () => debugSnippet(ctx)),
vscode.commands.registerCommand("swift.runPluginTask", () => runPluginTask()),
vscode.commands.registerCommand("swift.restartLSPServer", () =>
ctx.languageClientManager.restart()
),
vscode.commands.registerCommand("swift.reindexProject", () => reindexProject(ctx)),
vscode.commands.registerCommand("swift.insertFunctionComment", () =>
insertFunctionComment(ctx)
),
vscode.commands.registerCommand("swift.useLocalDependency", item => {
if (item instanceof PackageNode) {
useLocalDependency(item.name, ctx);
}
}),
vscode.commands.registerCommand("swift.editDependency", item => {
if (item instanceof PackageNode) {
editDependency(item.name, ctx);
}
}),
vscode.commands.registerCommand("swift.uneditDependency", item => {
if (item instanceof PackageNode) {
uneditDependency(item.name, ctx);
}
}),
vscode.commands.registerCommand("swift.openInWorkspace", item => {
if (item instanceof PackageNode) {
openInWorkspace(item);
}
}),
vscode.commands.registerCommand("swift.openExternal", item => {
if (item instanceof PackageNode) {
openInExternalEditor(item);
}
}),
vscode.commands.registerCommand("swift.attachDebugger", () => attachDebugger(ctx)),
vscode.commands.registerCommand("swift.clearDiagnosticsCollection", () =>
ctx.diagnostics.clear()
),
vscode.commands.registerCommand("swift.captureDiagnostics", () => captureDiagnostics(ctx)),
];
}