-
Notifications
You must be signed in to change notification settings - Fork 68
/
Copy pathconfiguration.ts
394 lines (383 loc) · 16.4 KB
/
configuration.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
//===----------------------------------------------------------------------===//
//
// This source file is part of the VS Code Swift open source project
//
// Copyright (c) 2021 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";
export type DebugAdapters = "auto" | "lldb-dap" | "CodeLLDB";
export type CFamilySupportOptions = "enable" | "disable" | "cpptools-inactive";
export type ActionAfterBuildError = "Focus Problems" | "Focus Terminal" | "Do Nothing";
export type OpenAfterCreateNewProjectOptions =
| "always"
| "alwaysNewWindow"
| "whenNoFolderOpen"
| "prompt";
export type ShowBuildStatusOptions = "never" | "swiftStatus" | "progress" | "notification";
export type DiagnosticCollectionOptions =
| "onlySwiftc"
| "onlySourceKit"
| "keepSwiftc"
| "keepSourceKit"
| "keepAll";
export type DiagnosticStyle = "default" | "llvm" | "swift";
/** sourcekit-lsp configuration */
export interface LSPConfiguration {
/** Path to sourcekit-lsp executable */
readonly serverPath: string;
/** Arguments to pass to sourcekit-lsp executable */
readonly serverArguments: string[];
/** Are inlay hints enabled */
readonly inlayHintsEnabled: boolean;
/** Support C Family source files */
readonly supportCFamily: CFamilySupportOptions;
/** Support Languages */
readonly supportedLanguages: string[];
/** Is SourceKit-LSP disabled */
readonly disable: boolean;
}
/** debugger configuration */
export interface DebuggerConfiguration {
/** Get the underlying debug adapter type requested by the user. */
readonly debugAdapter: DebugAdapters;
/** Return path to debug adapter */
readonly customDebugAdapterPath: string;
/** Whether or not to disable setting up the debugger */
readonly disable: boolean;
}
/** workspace folder configuration */
export interface FolderConfiguration {
/** Environment variables to set when running tests */
readonly testEnvironmentVariables: { [key: string]: string };
/** Extra arguments to set when building tests */
readonly additionalTestArguments: string[];
/** search sub-folder of workspace folder for Swift Packages */
readonly searchSubfoldersForPackages: boolean;
/** auto-generate launch.json configurations */
readonly autoGenerateLaunchConfigurations: boolean;
/** disable automatic running of swift package resolve */
readonly disableAutoResolve: boolean;
/** location to save swift-testing attachments */
readonly attachmentsPath: string;
/** look up saved permissions for the supplied plugin */
pluginPermissions(pluginId: string): PluginPermissionConfiguration;
}
export interface PluginPermissionConfiguration {
/** Disable using the sandbox when executing plugins */
disableSandbox?: boolean;
/** Allow the plugin to write to the package directory */
allowWritingToPackageDirectory?: boolean;
/** Allow the plugin to write to an additional directory or directories */
allowWritingToDirectory?: string | string[];
/**
* Allow the plugin to make network connections
* For a list of valid options see:
* https://github.com/swiftlang/swift-package-manager/blob/0401a2ae55077cfd1f4c0acd43ae0a1a56ab21ef/Sources/Commands/PackageCommands/PluginCommand.swift#L62
*/
allowNetworkConnections?: string;
}
/**
* Type-safe wrapper around configuration settings.
*/
const configuration = {
/** sourcekit-lsp configuration */
get lsp(): LSPConfiguration {
return {
get serverPath(): string {
return vscode.workspace
.getConfiguration("swift.sourcekit-lsp")
.get<string>("serverPath", "");
},
get serverArguments(): string[] {
return vscode.workspace
.getConfiguration("swift.sourcekit-lsp")
.get<string[]>("serverArguments", []);
},
get inlayHintsEnabled(): boolean {
return vscode.workspace
.getConfiguration("sourcekit-lsp")
.get<boolean>("inlayHints.enabled", true);
},
get supportCFamily(): CFamilySupportOptions {
return vscode.workspace
.getConfiguration("sourcekit-lsp")
.get<CFamilySupportOptions>("support-c-cpp", "cpptools-inactive");
},
get supportedLanguages() {
return vscode.workspace
.getConfiguration("swift.sourcekit-lsp")
.get("supported-languages", [
"swift",
"c",
"cpp",
"objective-c",
"objective-cpp",
]);
},
get disable(): boolean {
return vscode.workspace
.getConfiguration("swift.sourcekit-lsp")
.get<boolean>("disable", false);
},
};
},
folder(workspaceFolder: vscode.WorkspaceFolder): FolderConfiguration {
return {
/** Environment variables to set when running tests */
get testEnvironmentVariables(): { [key: string]: string } {
return vscode.workspace
.getConfiguration("swift", workspaceFolder)
.get<{ [key: string]: string }>("testEnvironmentVariables", {});
},
/** Extra arguments to pass to swift test and swift build when running and debugging tests. */
get additionalTestArguments(): string[] {
return vscode.workspace
.getConfiguration("swift", workspaceFolder)
.get<string[]>("additionalTestArguments", []);
},
/** auto-generate launch.json configurations */
get autoGenerateLaunchConfigurations(): boolean {
return vscode.workspace
.getConfiguration("swift", workspaceFolder)
.get<boolean>("autoGenerateLaunchConfigurations", true);
},
/** disable automatic running of swift package resolve */
get disableAutoResolve(): boolean {
return vscode.workspace
.getConfiguration("swift", workspaceFolder)
.get<boolean>("disableAutoResolve", false);
},
/** search sub-folder of workspace folder for Swift Packages */
get searchSubfoldersForPackages(): boolean {
return vscode.workspace
.getConfiguration("swift", workspaceFolder)
.get<boolean>("searchSubfoldersForPackages", false);
},
get attachmentsPath(): string {
return vscode.workspace
.getConfiguration("swift", workspaceFolder)
.get<string>("attachmentsPath", "./.build/attachments");
},
pluginPermissions(pluginId: string): PluginPermissionConfiguration {
return (
vscode.workspace.getConfiguration("swift", workspaceFolder).get<{
[key: string]: PluginPermissionConfiguration;
}>("pluginPermissions", {})[pluginId] ?? {}
);
},
};
},
/** debugger configuration */
get debugger(): DebuggerConfiguration {
return {
get debugAdapter(): DebugAdapters {
// Use inspect to determine if the user has explicitly set swift.debugger.useDebugAdapterFromToolchain
const inspectUseDebugAdapterFromToolchain = vscode.workspace
.getConfiguration("swift.debugger")
.inspect<boolean>("useDebugAdapterFromToolchain");
let useDebugAdapterFromToolchain =
inspectUseDebugAdapterFromToolchain?.workspaceValue ??
inspectUseDebugAdapterFromToolchain?.globalValue;
// On Windows arm64 we enable swift.debugger.useDebugAdapterFromToolchain by default since CodeLLDB does
// not support this platform and gives an awful error message.
if (process.platform === "win32" && process.arch === "arm64") {
useDebugAdapterFromToolchain = useDebugAdapterFromToolchain ?? true;
}
const selectedAdapter = vscode.workspace
.getConfiguration("swift.debugger")
.get<DebugAdapters>("debugAdapter", "auto");
switch (selectedAdapter) {
case "auto":
if (useDebugAdapterFromToolchain !== undefined) {
return useDebugAdapterFromToolchain ? "lldb-dap" : "CodeLLDB";
}
return "auto";
default:
return selectedAdapter;
}
},
get customDebugAdapterPath(): string {
return vscode.workspace.getConfiguration("swift.debugger").get<string>("path", "");
},
get disable(): boolean {
return vscode.workspace
.getConfiguration("swift.debugger")
.get<boolean>("disable", false);
},
};
},
/** Files and directories to exclude from the code coverage. */
get excludeFromCodeCoverage(): string[] {
return vscode.workspace
.getConfiguration("swift")
.get<string[]>("excludeFromCodeCoverage", []);
},
/** Files and directories to exclude from the Package Dependencies view. */
get excludePathsFromPackageDependencies(): string[] {
return vscode.workspace
.getConfiguration("swift")
.get<string[]>("excludePathsFromPackageDependencies", []);
},
/** Path to folder that include swift executable */
get path(): string {
return vscode.workspace.getConfiguration("swift").get<string>("path", "");
},
/** Path to folder that include swift runtime */
get runtimePath(): string {
return vscode.workspace.getConfiguration("swift").get<string>("runtimePath", "");
},
/** Path to custom --sdk */
get sdk(): string {
return vscode.workspace.getConfiguration("swift").get<string>("SDK", "");
},
set sdk(value: string | undefined) {
vscode.workspace.getConfiguration("swift").update("SDK", value);
},
/** Path to custom --swift-sdk */
get swiftSDK(): string {
return vscode.workspace.getConfiguration("swift").get<string>("swiftSDK", "");
},
set swiftSDK(value: string | undefined) {
vscode.workspace.getConfiguration("swift").update("swiftSDK", value);
},
/** swift build arguments */
get buildArguments(): string[] {
return vscode.workspace.getConfiguration("swift").get<string[]>("buildArguments", []);
},
/** swift package arguments */
get packageArguments(): string[] {
return vscode.workspace.getConfiguration("swift").get<string[]>("packageArguments", []);
},
/** thread/address sanitizer */
get sanitizer(): string {
return vscode.workspace.getConfiguration("swift").get<string>("sanitizer", "off");
},
get buildPath(): string {
return vscode.workspace.getConfiguration("swift").get<string>("buildPath", "");
},
get disableSwiftPMIntegration(): boolean {
return vscode.workspace
.getConfiguration("swift")
.get<boolean>("disableSwiftPackageManagerIntegration", false);
},
/** Environment variables to set when building */
get swiftEnvironmentVariables(): { [key: string]: string } {
return vscode.workspace
.getConfiguration("swift")
.get<{ [key: string]: string }>("swiftEnvironmentVariables", {});
},
/** include build errors in problems view */
get diagnosticsCollection(): DiagnosticCollectionOptions {
return vscode.workspace
.getConfiguration("swift")
.get<DiagnosticCollectionOptions>("diagnosticsCollection", "keepSourceKit");
},
/** set the -diagnostic-style option when running `swift` tasks */
get diagnosticsStyle(): DiagnosticStyle {
return vscode.workspace
.getConfiguration("swift")
.get<DiagnosticStyle>("diagnosticsStyle", "llvm");
},
/** where to show the build progress for the running task */
get showBuildStatus(): ShowBuildStatusOptions {
return vscode.workspace
.getConfiguration("swift")
.get<ShowBuildStatusOptions>("showBuildStatus", "swiftStatus");
},
/** background compilation */
get backgroundCompilation(): boolean {
return vscode.workspace
.getConfiguration("swift")
.get<boolean>("backgroundCompilation", false);
},
/** background indexing */
get backgroundIndexing(): "on" | "off" | "auto" {
const value = vscode.workspace
.getConfiguration("swift.sourcekit-lsp")
.get("backgroundIndexing", "auto");
// Legacy versions of this setting were a boolean, convert to the new string version.
if (typeof value === "boolean") {
return value ? "on" : "off";
} else {
return value;
}
},
/** focus on problems view whenever there is a build error */
get actionAfterBuildError(): ActionAfterBuildError {
return vscode.workspace
.getConfiguration("swift")
.get<ActionAfterBuildError>("actionAfterBuildError", "Focus Terminal");
},
/** output additional diagnostics */
get diagnostics(): boolean {
return vscode.workspace.getConfiguration("swift").get<boolean>("diagnostics", false);
},
/**
* Test coverage settings
*/
/** Should test coverage report be displayed after running test coverage */
get displayCoverageReportAfterRun(): boolean {
return vscode.workspace
.getConfiguration("swift")
.get<boolean>("coverage.displayReportAfterRun", true);
},
get alwaysShowCoverageStatusItem(): boolean {
return vscode.workspace
.getConfiguration("swift")
.get<boolean>("coverage.alwaysShowStatusItem", true);
},
get coverageHitColorLightMode(): string {
return vscode.workspace
.getConfiguration("swift")
.get<string>("coverage.colors.lightMode.hit", "#c0ffc0");
},
get coverageMissColorLightMode(): string {
return vscode.workspace
.getConfiguration("swift")
.get<string>("coverage.colors.lightMode.miss", "#ffc0c0");
},
get coverageHitColorDarkMode(): string {
return vscode.workspace
.getConfiguration("swift")
.get<string>("coverage.colors.darkMode.hit", "#003000");
},
get coverageMissColorDarkMode(): string {
return vscode.workspace
.getConfiguration("swift")
.get<string>("coverage.colors.darkMode.miss", "#400000");
},
get openAfterCreateNewProject(): OpenAfterCreateNewProjectOptions {
return vscode.workspace
.getConfiguration("swift")
.get<OpenAfterCreateNewProjectOptions>("openAfterCreateNewProject", "prompt");
},
/** Whether or not the extension should warn about being unable to create symlinks on Windows */
get warnAboutSymlinkCreation(): boolean {
return vscode.workspace
.getConfiguration("swift")
.get<boolean>("warnAboutSymlinkCreation", true);
},
set warnAboutSymlinkCreation(value: boolean) {
vscode.workspace
.getConfiguration("swift")
.update("warnAboutSymlinkCreation", value, vscode.ConfigurationTarget.Global);
},
/** Whether or not the extension will contribute Swift environment variables to the integrated terminal */
get enableTerminalEnvironment(): boolean {
return vscode.workspace
.getConfiguration("swift")
.get<boolean>("enableTerminalEnvironment", true);
},
/** Whether or not to disable SwiftPM sandboxing */
get disableSandbox(): boolean {
return vscode.workspace.getConfiguration("swift").get<boolean>("disableSandbox", false);
},
};
export default configuration;