-
Notifications
You must be signed in to change notification settings - Fork 31.8k
/
Copy pathenvironmentService.ts
264 lines (208 loc) · 8.87 KB
/
environmentService.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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Schemas } from 'vs/base/common/network';
import { joinPath } from 'vs/base/common/resources';
import { URI } from 'vs/base/common/uri';
import { generateUuid } from 'vs/base/common/uuid';
import { BACKUPS, IExtensionHostDebugParams } from 'vs/platform/environment/common/environment';
import { IPath } from 'vs/platform/windows/common/windows';
import { IWorkbenchEnvironmentService, IEnvironmentConfiguration } from 'vs/workbench/services/environment/common/environmentService';
import { IWorkbenchConstructionOptions } from 'vs/workbench/workbench.web.api';
import product from 'vs/platform/product/common/product';
import { memoize } from 'vs/base/common/decorators';
import { onUnexpectedError } from 'vs/base/common/errors';
export class BrowserEnvironmentConfiguration implements IEnvironmentConfiguration {
constructor(
private readonly options: IBrowserWorkbenchEnvironmentConstructionOptions,
private readonly payload: Map<string, string> | undefined,
private readonly backupHome: URI
) { }
@memoize
get sessionId(): string { return generateUuid(); }
@memoize
get remoteAuthority(): string | undefined { return this.options.remoteAuthority; }
@memoize
get backupWorkspaceResource(): URI { return joinPath(this.backupHome, this.options.workspaceId); }
@memoize
get filesToOpenOrCreate(): IPath[] | undefined {
if (this.payload) {
const fileToOpen = this.payload.get('openFile');
if (fileToOpen) {
return [{ fileUri: URI.parse(fileToOpen) }];
}
}
return undefined;
}
@memoize
get filesToDiff(): IPath[] | undefined {
if (this.payload) {
const fileToDiffDetail = this.payload.get('diffFileDetail');
const fileToDiffMaster = this.payload.get('diffFileMaster');
if (fileToDiffDetail && fileToDiffMaster) {
return [
{ fileUri: URI.parse(fileToDiffDetail) },
{ fileUri: URI.parse(fileToDiffMaster) }
];
}
}
return undefined;
}
get highContrast() {
return false; // could investigate to detect high contrast theme automatically
}
}
interface IBrowserWorkbenchEnvironmentConstructionOptions extends IWorkbenchConstructionOptions {
workspaceId: string;
logsPath: URI;
}
interface IExtensionHostDebugEnvironment {
params: IExtensionHostDebugParams;
isExtensionDevelopment: boolean;
extensionDevelopmentLocationURI?: URI[];
extensionTestsLocationURI?: URI;
extensionEnabledProposedApi?: string[];
}
export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironmentService {
_serviceBrand: undefined;
private _configuration: IEnvironmentConfiguration | undefined = undefined;
get configuration(): IEnvironmentConfiguration {
if (!this._configuration) {
this._configuration = new BrowserEnvironmentConfiguration(this.options, this.payload, this.backupHome);
}
return this._configuration;
}
@memoize
get isBuilt(): boolean { return !!product.commit; }
@memoize
get logsPath(): string { return this.options.logsPath.path; }
get logLevel(): string | undefined { return this.payload?.get('logLevel'); }
@memoize
get logFile(): URI { return joinPath(this.options.logsPath, 'window.log'); }
@memoize
get userRoamingDataHome(): URI { return URI.file('/User').with({ scheme: Schemas.userData }); }
@memoize
get settingsResource(): URI { return joinPath(this.userRoamingDataHome, 'settings.json'); }
@memoize
get argvResource(): URI { return joinPath(this.userRoamingDataHome, 'argv.json'); }
@memoize
get snippetsHome(): URI { return joinPath(this.userRoamingDataHome, 'snippets'); }
/*
* In Web every workspace can potentially have scoped user-data and/or extensions and if Sync state is shared then it can make
* Sync error prone - say removing extensions from another workspace. Hence scope Sync state per workspace.
* Sync scoped to a workspace is capable of handling opening same workspace in multiple windows.
*/
@memoize
get userDataSyncHome(): URI { return joinPath(this.userRoamingDataHome, 'sync', this.options.workspaceId); }
@memoize
get userDataSyncLogResource(): URI { return joinPath(this.options.logsPath, 'userDataSync.log'); }
@memoize
get sync(): 'on' | 'off' | undefined { return undefined; }
@memoize
get enableSyncByDefault(): boolean { return !!this.options.enableSyncByDefault; }
@memoize
get keybindingsResource(): URI { return joinPath(this.userRoamingDataHome, 'keybindings.json'); }
@memoize
get keyboardLayoutResource(): URI { return joinPath(this.userRoamingDataHome, 'keyboardLayout.json'); }
@memoize
get backupHome(): URI { return joinPath(this.userRoamingDataHome, BACKUPS); }
@memoize
get untitledWorkspacesHome(): URI { return joinPath(this.userRoamingDataHome, 'Workspaces'); }
@memoize
get serviceMachineIdResource(): URI { return joinPath(this.userRoamingDataHome, 'machineid'); }
private _extensionHostDebugEnvironment: IExtensionHostDebugEnvironment | undefined = undefined;
get debugExtensionHost(): IExtensionHostDebugParams {
if (!this._extensionHostDebugEnvironment) {
this._extensionHostDebugEnvironment = this.resolveExtensionHostDebugEnvironment();
}
return this._extensionHostDebugEnvironment.params;
}
get isExtensionDevelopment(): boolean {
if (!this._extensionHostDebugEnvironment) {
this._extensionHostDebugEnvironment = this.resolveExtensionHostDebugEnvironment();
}
return this._extensionHostDebugEnvironment.isExtensionDevelopment;
}
get extensionDevelopmentLocationURI(): URI[] | undefined {
if (!this._extensionHostDebugEnvironment) {
this._extensionHostDebugEnvironment = this.resolveExtensionHostDebugEnvironment();
}
return this._extensionHostDebugEnvironment.extensionDevelopmentLocationURI;
}
get extensionTestsLocationURI(): URI | undefined {
if (!this._extensionHostDebugEnvironment) {
this._extensionHostDebugEnvironment = this.resolveExtensionHostDebugEnvironment();
}
return this._extensionHostDebugEnvironment.extensionTestsLocationURI;
}
get extensionEnabledProposedApi(): string[] | undefined {
if (!this._extensionHostDebugEnvironment) {
this._extensionHostDebugEnvironment = this.resolveExtensionHostDebugEnvironment();
}
return this._extensionHostDebugEnvironment.extensionEnabledProposedApi;
}
get disableExtensions() { return this.payload?.get('disableExtensions') === 'true'; }
@memoize
get webviewExternalEndpoint(): string {
// TODO@matt: get fallback from product.json
return (this.options.webviewEndpoint || 'https://{{uuid}}.vscode-webview-test.com/{{commit}}').replace('{{commit}}', product.commit || '0d728c31ebdf03869d2687d9be0b017667c9ff37');
}
@memoize
get webviewResourceRoot(): string {
return `${this.webviewExternalEndpoint}/vscode-resource/{{resource}}`;
}
@memoize
get webviewCspSource(): string {
return this.webviewExternalEndpoint.replace('{{uuid}}', '*');
}
get disableTelemetry(): boolean { return false; }
get verbose(): boolean { return this.payload?.get('verbose') === 'true'; }
get logExtensionHostCommunication(): boolean { return this.payload?.get('logExtensionHostCommunication') === 'true'; }
private payload: Map<string, string> | undefined;
constructor(readonly options: IBrowserWorkbenchEnvironmentConstructionOptions) {
if (options.workspaceProvider && Array.isArray(options.workspaceProvider.payload)) {
try {
this.payload = new Map(options.workspaceProvider.payload);
} catch (error) {
onUnexpectedError(error); // possible invalid payload for map
}
}
}
private resolveExtensionHostDebugEnvironment(): IExtensionHostDebugEnvironment {
const extensionHostDebugEnvironment: IExtensionHostDebugEnvironment = {
params: {
port: null,
break: false
},
isExtensionDevelopment: false,
extensionDevelopmentLocationURI: undefined
};
// Fill in selected extra environmental properties
if (this.payload) {
for (const [key, value] of this.payload) {
switch (key) {
case 'extensionDevelopmentPath':
extensionHostDebugEnvironment.extensionDevelopmentLocationURI = [URI.parse(value)];
extensionHostDebugEnvironment.isExtensionDevelopment = true;
break;
case 'extensionTestsPath':
extensionHostDebugEnvironment.extensionTestsLocationURI = URI.parse(value);
break;
case 'debugId':
extensionHostDebugEnvironment.params.debugId = value;
break;
case 'inspect-brk-extensions':
extensionHostDebugEnvironment.params.port = parseInt(value);
extensionHostDebugEnvironment.params.break = true;
break;
case 'enableProposedApi':
extensionHostDebugEnvironment.extensionEnabledProposedApi = [];
break;
}
}
}
return extensionHostDebugEnvironment;
}
get skipReleaseNotes(): boolean { return false; }
}