forked from swiftlang/vscode-swift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfiguration.ts
318 lines (309 loc) · 12.9 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
//===----------------------------------------------------------------------===//
//
// 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";
type CFamilySupportOptions = "enable" | "disable" | "cpptools-inactive";
type ActionAfterBuildError = "Focus Problems" | "Focus Terminal" | "Do Nothing";
type OpenAfterCreateNewProjectOptions =
| "always"
| "alwaysNewWindow"
| "whenNoFolderOpen"
| "prompt";
export type ShowBuildStatusOptions = "never" | "swiftStatus" | "progress" | "notification";
export type DiagnosticCollectionOptions =
| "onlySwiftc"
| "onlySourceKit"
| "keepSwiftc"
| "keepSourceKit"
| "keepAll";
/** 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 {
/** Whether or not to use CodeLLDB for debugging instead of lldb-dap */
readonly useDebugAdapterFromToolchain: boolean;
/** Return path to debug adapter */
readonly customDebugAdapterPath: string;
}
/** 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;
}
/**
* 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);
},
};
},
/** debugger configuration */
get debugger(): DebuggerConfiguration {
return {
get useDebugAdapterFromToolchain(): boolean {
// Enabled by default only when we're on Windows arm64 since CodeLLDB does not support
// this platform and gives an awful error message.
if (process.platform === "win32" && process.arch === "arm64") {
// We need to use inspect to find out if the value is explicitly set.
const inspect = vscode.workspace
.getConfiguration("swift.debugger")
.inspect<boolean>("useDebugAdapterFromToolchain");
return inspect?.workspaceValue ?? inspect?.globalValue ?? true;
}
return vscode.workspace
.getConfiguration("swift.debugger")
.get<boolean>("useDebugAdapterFromToolchain", false);
},
get customDebugAdapterPath(): string {
return vscode.workspace.getConfiguration("swift.debugger").get<string>("path", "");
},
};
},
/** 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 swift sdk */
get sdk(): string {
return vscode.workspace.getConfiguration("swift").get<string>("SDK", "");
},
set sdk(value: string | undefined) {
vscode.workspace.getConfiguration("swift").update("SDK", value);
},
/** swift build arguments */
get buildArguments(): string[] {
return vscode.workspace.getConfiguration("swift").get<string[]>("buildArguments", []);
},
/** 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(): "default" | "llvm" | "swift" {
return vscode.workspace.getConfiguration("swift").get("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(): boolean {
return vscode.workspace
.getConfiguration("swift.sourcekit-lsp")
.get("backgroundIndexing", false);
},
/** 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);
},
};
export default configuration;