forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathenvironmentService.ts
352 lines (285 loc) · 12.6 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
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
/*---------------------------------------------------------------------------------------------
* 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 { IExtensionHostDebugParams } from 'vs/platform/environment/common/environment';
import { IPath, IWindowConfiguration } from 'vs/platform/windows/common/windows';
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
import type { IWorkbenchConstructionOptions as IWorkbenchOptions } from 'vs/workbench/workbench.web.api';
import { IProductService } from 'vs/platform/product/common/productService';
import { memoize } from 'vs/base/common/decorators';
import { onUnexpectedError } from 'vs/base/common/errors';
import { parseLineAndColumnAware } from 'vs/base/common/extpath';
import { LogLevelToString } from 'vs/platform/log/common/log';
import { ExtensionKind } from 'vs/platform/extensions/common/extensions';
import { isUndefined } from 'vs/base/common/types';
class BrowserWorkbenchConfiguration implements IWindowConfiguration {
constructor(
private readonly options: IBrowserWorkbenchOptions,
private readonly payload: Map<string, string> | undefined
) { }
@memoize
get sessionId(): string { return generateUuid(); }
@memoize
get remoteAuthority(): string | undefined { return this.options.remoteAuthority; }
@memoize
get filesToOpenOrCreate(): IPath[] | undefined {
if (this.payload) {
const fileToOpen = this.payload.get('openFile');
if (fileToOpen) {
const fileUri = URI.parse(fileToOpen);
// Support: --goto parameter to open on line/col
if (this.payload.has('gotoLineMode')) {
const pathColumnAware = parseLineAndColumnAware(fileUri.path);
return [{
fileUri: fileUri.with({ path: pathColumnAware.path }),
selection: !isUndefined(pathColumnAware.line) ? { startLineNumber: pathColumnAware.line, startColumn: pathColumnAware.column || 1 } : undefined
}];
}
return [{ fileUri }];
}
}
return undefined;
}
@memoize
get filesToDiff(): IPath[] | undefined {
if (this.payload) {
const fileToDiffPrimary = this.payload.get('diffFilePrimary');
const fileToDiffSecondary = this.payload.get('diffFileSecondary');
if (fileToDiffPrimary && fileToDiffSecondary) {
return [
{ fileUri: URI.parse(fileToDiffSecondary) },
{ fileUri: URI.parse(fileToDiffPrimary) }
];
}
}
return undefined;
}
}
interface IBrowserWorkbenchOptions extends IWorkbenchOptions {
workspaceId: string;
logsPath: URI;
}
interface IExtensionHostDebugEnvironment {
params: IExtensionHostDebugParams;
debugRenderer: boolean;
isExtensionDevelopment: boolean;
extensionDevelopmentLocationURI?: URI[];
extensionDevelopmentKind?: ExtensionKind[];
extensionTestsLocationURI?: URI;
extensionEnabledProposedApi?: string[];
}
export class BrowserWorkbenchEnvironmentService implements IWorkbenchEnvironmentService {
declare readonly _serviceBrand: undefined;
private _configuration: IWindowConfiguration | undefined = undefined;
get configuration(): IWindowConfiguration {
if (!this._configuration) {
this._configuration = new BrowserWorkbenchConfiguration(this.options, this.payload);
}
return this._configuration;
}
@memoize
get remoteAuthority(): string | undefined { return this.options.remoteAuthority; }
@memoize
get isBuilt(): boolean { return !!this.productService.commit; }
@memoize
get logsPath(): string { return this.options.logsPath.path; }
@memoize
get logLevel(): string | undefined { return this.payload?.get('logLevel') || (this.options.developmentOptions?.logLevel !== undefined ? LogLevelToString(this.options.developmentOptions?.logLevel) : undefined); }
@memoize
get logFile(): URI { return joinPath(this.options.logsPath, 'window.log'); }
/**
* Use the local disk. This solves two problems:
* 1. Extensions running in the browser (like Vim) might use these paths
* directly instead of using the file service and most likely can't write
* to `/User` on disk.
* 2. Settings will be stored in the file system instead of in browser
* storage. Using browser storage makes sharing or seeding settings
* between browsers difficult. We may want to revisit this once/if we get
* settings sync.
* @author coder
*/
@memoize
get userRoamingDataHome(): URI { return joinPath(URI.file(this.userDataPath).with({ scheme: Schemas.vscodeRemote }), 'User'); }
@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'); }
@memoize
get cacheHome(): URI { return joinPath(this.userRoamingDataHome, 'caches'); }
@memoize
get globalStorageHome(): URI { return URI.joinPath(this.userRoamingDataHome, 'globalStorage'); }
@memoize
get workspaceStorageHome(): URI { return URI.joinPath(this.userRoamingDataHome, 'workspaceStorage'); }
/*
* 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 keybindingsResource(): URI { return joinPath(this.userRoamingDataHome, 'keybindings.json'); }
@memoize
get keyboardLayoutResource(): URI { return joinPath(this.userRoamingDataHome, 'keyboardLayout.json'); }
@memoize
get untitledWorkspacesHome(): URI { return joinPath(this.userRoamingDataHome, 'Workspaces'); }
@memoize
get serviceMachineIdResource(): URI { return joinPath(this.userRoamingDataHome, 'machineid'); }
@memoize
get extHostLogsPath(): URI { return joinPath(this.options.logsPath, 'exthost'); }
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 extensionDevelopmentLocationKind(): ExtensionKind[] | undefined {
if (!this._extensionHostDebugEnvironment) {
this._extensionHostDebugEnvironment = this.resolveExtensionHostDebugEnvironment();
}
return this._extensionHostDebugEnvironment.extensionDevelopmentKind;
}
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 debugRenderer(): boolean {
if (!this._extensionHostDebugEnvironment) {
this._extensionHostDebugEnvironment = this.resolveExtensionHostDebugEnvironment();
}
return this._extensionHostDebugEnvironment.debugRenderer;
}
get disableExtensions() { return this.payload?.get('disableExtensions') === 'true'; }
get enableExtensions() { return this.options.enabledExtensions; }
@memoize
get webviewExternalEndpoint(): string {
const endpoint = this.options.webviewEndpoint
|| this.productService.webviewContentExternalBaseUrlTemplate
|| 'https://{{uuid}}.vscode-webview.net/{{quality}}/{{commit}}/out/vs/workbench/contrib/webview/browser/pre/';
const webviewExternalEndpointCommit = this.payload?.get('webviewExternalEndpointCommit');
return endpoint
.replace('{{commit}}', webviewExternalEndpointCommit ?? this.productService.commit ?? 'dc1a6699060423b8c4d2ced736ad70195378fddf')
.replace('{{quality}}', (webviewExternalEndpointCommit ? 'insider' : this.productService.quality) ?? 'insider');
}
@memoize
get telemetryLogResource(): URI { return joinPath(this.options.logsPath, 'telemetry.log'); }
get disableTelemetry(): boolean { return false; }
get verbose(): boolean { return this.payload?.get('verbose') === 'true'; }
get logExtensionHostCommunication(): boolean { return this.payload?.get('logExtensionHostCommunication') === 'true'; }
get skipReleaseNotes(): boolean { return false; }
get skipWelcome(): boolean { return this.payload?.get('skipWelcome') === 'true'; }
@memoize
get disableWorkspaceTrust(): boolean { return true; }
//#region @coder
get userDataPath(): string {
if (!this.options.userDataPath) {
throw new Error('userDataPath was not provided to the browser');
}
return this.options.userDataPath;
}
//#endregion
private payload: Map<string, string> | undefined;
constructor(
readonly options: IBrowserWorkbenchOptions,
private readonly productService: IProductService
) {
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
},
debugRenderer: false,
isExtensionDevelopment: false,
extensionDevelopmentLocationURI: undefined,
extensionDevelopmentKind: undefined
};
// Fill in selected extra environmental properties
if (this.payload) {
for (const [key, value] of this.payload) {
switch (key) {
case 'extensionDevelopmentPath':
if (!extensionHostDebugEnvironment.extensionDevelopmentLocationURI) {
extensionHostDebugEnvironment.extensionDevelopmentLocationURI = [];
}
extensionHostDebugEnvironment.extensionDevelopmentLocationURI.push(URI.parse(value));
extensionHostDebugEnvironment.isExtensionDevelopment = true;
break;
case 'extensionDevelopmentKind':
extensionHostDebugEnvironment.extensionDevelopmentKind = [<ExtensionKind>value];
break;
case 'extensionTestsPath':
extensionHostDebugEnvironment.extensionTestsLocationURI = URI.parse(value);
break;
case 'debugRenderer':
extensionHostDebugEnvironment.debugRenderer = value === 'true';
break;
case 'debugId':
extensionHostDebugEnvironment.params.debugId = value;
break;
case 'inspect-brk-extensions':
extensionHostDebugEnvironment.params.port = parseInt(value);
extensionHostDebugEnvironment.params.break = true;
break;
case 'inspect-extensions':
extensionHostDebugEnvironment.params.port = parseInt(value);
break;
case 'enableProposedApi':
extensionHostDebugEnvironment.extensionEnabledProposedApi = [];
break;
}
}
}
const developmentOptions = this.options.developmentOptions;
if (developmentOptions && !extensionHostDebugEnvironment.isExtensionDevelopment) {
if (developmentOptions.extensions?.length) {
extensionHostDebugEnvironment.extensionDevelopmentLocationURI = developmentOptions.extensions.map(e => URI.revive(e));
extensionHostDebugEnvironment.isExtensionDevelopment = true;
}
if (developmentOptions.extensionTestsPath) {
extensionHostDebugEnvironment.extensionTestsLocationURI = URI.revive(developmentOptions.extensionTestsPath);
}
}
return extensionHostDebugEnvironment;
}
}