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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import 'vs/workbench/workbench.web.main';
import { main } from 'vs/workbench/browser/web.main';
import { UriComponents, URI } from 'vs/base/common/uri';
import { IFileSystemProvider, FileSystemProviderCapabilities, IFileChange, FileChangeType } from 'vs/platform/files/common/files';
import { IWebSocketFactory, IWebSocket } from 'vs/platform/remote/browser/browserSocketFactory';
import { ICredentialsProvider } from 'vs/workbench/services/credentials/browser/credentialsService';
import { IExtensionManifest } from 'vs/platform/extensions/common/extensions';
import { IURLCallbackProvider } from 'vs/workbench/services/url/browser/urlService';
import { LogLevel } from 'vs/platform/log/common/log';
import { IUpdateProvider, IUpdate } from 'vs/workbench/services/update/browser/updateService';
import { Event, Emitter } from 'vs/base/common/event';
import { Disposable, IDisposable } from 'vs/base/common/lifecycle';
import { IWorkspaceProvider, IWorkspace } from 'vs/workbench/services/host/browser/browserHostService';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
interface IResourceUriProvider {
(uri: URI): URI;
}
interface IStaticExtension {
packageJSON: IExtensionManifest;
extensionLocation: URI;
}
interface ICommontTelemetryPropertiesResolver {
(): { [key: string]: any };
}
interface IExternalUriResolver {
(uri: URI): Promise<URI>;
}
interface ITunnelProvider {
/**
* Support for creating tunnels.
*/
tunnelFactory?: ITunnelFactory;
/**
* Support for filtering candidate ports
*/
showPortCandidate?: IShowPortCandidate;
}
interface ITunnelFactory {
(tunnelOptions: ITunnelOptions): Promise<ITunnel> | undefined;
}
interface ITunnelOptions {
remoteAddress: { port: number, host: string };
/**
* The desired local port. If this port can't be used, then another will be chosen.
*/
localAddressPort?: number;
label?: string;
}
interface ITunnel extends IDisposable {
remoteAddress: { port: number, host: string };
/**
* The complete local address(ex. localhost:1234)
*/
localAddress: string;
/**
* Implementers of Tunnel should fire onDidDispose when dispose is called.
*/
onDidDispose: Event<void>;
}
interface IShowPortCandidate {
(host: string, port: number, detail: string): Promise<boolean>;
}
interface ICommand {
/**
* An identifier for the command. Commands can be executed from extensions
* using the `vscode.commands.executeCommand` API using that command ID.
*/
id: string,
/**
* A function that is being executed with any arguments passed over. The
* return type will be send back to the caller.
*
* Note: arguments and return type should be serializable so that they can
* be exchanged across processes boundaries.
*/
handler: (...args: any[]) => unknown;
}
interface IHomeIndicator {
/**
* The link to open when clicking the home indicator.
*/
href: string;
/**
* @deprecated use `href` instead.
*/
command?: string;
/**
* The icon name for the home indicator. This needs to be one of the existing
* icons from our Codicon icon set. For example `sync`.
*/
icon: string;
/**
* A tooltip that will appear while hovering over the home indicator.
*/
title: string;
}
interface IDefaultSideBarLayout {
visible?: boolean;
containers?: ({
id: 'explorer' | 'run' | 'scm' | 'search' | 'extensions' | 'remote' | string;
active: true;
order?: number;
views?: {
id: string;
order?: number;
visible?: boolean;
collapsed?: boolean;
}[];
} | {
id: 'explorer' | 'run' | 'scm' | 'search' | 'extensions' | 'remote' | string;
active?: false;
order?: number;
visible?: boolean;
views?: {
id: string;
order?: number;
visible?: boolean;
collapsed?: boolean;
}[];
})[];
}
interface IDefaultPanelLayout {
visible?: boolean;
containers?: ({
id: 'terminal' | 'debug' | 'problems' | 'output' | 'comments' | string;
order?: number;
active: true;
} | {
id: 'terminal' | 'debug' | 'problems' | 'output' | 'comments' | string;
order?: number;
active?: false;
visible?: boolean;
})[];
}
interface IDefaultEditor {
readonly uri: UriComponents;
readonly openOnlyIfExists?: boolean;
}
interface IDefaultLayout {
readonly sidebar?: IDefaultSideBarLayout;
readonly panel?: IDefaultPanelLayout;
readonly editors?: IDefaultEditor[];
}
interface IWorkbenchConstructionOptions {
//#region Connection related configuration
/**
* The remote authority is the IP:PORT from where the workbench is served
* from. It is for example being used for the websocket connections as address.
*/
readonly remoteAuthority?: string;
/**
* The connection token to send to the server.
*/
readonly connectionToken?: string;
/**
* An endpoint to serve iframe content ("webview") from. This is required
* to provide full security isolation from the workbench host.
*/
readonly webviewEndpoint?: string;
/**
* A factory for web sockets.
*/
readonly webSocketFactory?: IWebSocketFactory;
/**
* A provider for resource URIs.
*/
readonly resourceUriProvider?: IResourceUriProvider;
/**
* Resolves an external uri before it is opened.
*/
readonly resolveExternalUri?: IExternalUriResolver;
/**
* A provider for supplying tunneling functionality,
* such as creating tunnels and showing candidate ports to forward.
*/
readonly tunnelProvider?: ITunnelProvider;
//#endregion
//#region Workbench configuration
/**
* A handler for opening workspaces and providing the initial workspace.
*/
readonly workspaceProvider?: IWorkspaceProvider;
/**
* The user data provider is used to handle user specific application
* state like settings, keybindings, UI state (e.g. opened editors) and snippets.
*/
userDataProvider?: IFileSystemProvider;
/**
* Session id of the current authenticated user
*/
readonly authenticationSessionId?: string;
/**
* Enables user data sync by default and syncs into the current authenticated user account using the provided [authenticationSessionId}(#authenticationSessionId).
*/
readonly enableSyncByDefault?: boolean;
/**
* The credentials provider to store and retrieve secrets.
*/
readonly credentialsProvider?: ICredentialsProvider;
/**
* Add static extensions that cannot be uninstalled but only be disabled.
*/
readonly staticExtensions?: ReadonlyArray<IStaticExtension>;
/**
* Support for URL callbacks.
*/
readonly urlCallbackProvider?: IURLCallbackProvider;
/**
* Support for update reporting.
*/
readonly updateProvider?: IUpdateProvider;
/**
* Support adding additional properties to telemetry.
*/
readonly resolveCommonTelemetryProperties?: ICommontTelemetryPropertiesResolver;
/**
* A set of optional commands that should be registered with the commands
* registry.
*
* Note: commands can be called from extensions if the identifier is known!
*/
readonly commands?: readonly ICommand[];
/**
* Optional home indicator to appear above the hamburger menu in the activity bar.
*/
readonly homeIndicator?: IHomeIndicator;
/**
* Optional default layout to apply on first time the workspace is opened.
*/
readonly defaultLayout?: IDefaultLayout;
//#endregion
//#region Diagnostics
/**
* Current logging level. Default is `LogLevel.Info`.
*/
readonly logLevel?: LogLevel;
/**
* Whether to enable the smoke test driver.
*/
readonly driver?: boolean;
//#endregion
}
interface IWorkbench {
commands: {
executeCommand(command: string, ...args: any[]): Promise<unknown>;
}
}
/**
* Creates the workbench with the provided options in the provided container.
*
* @param domElement the container to create the workbench in
* @param options for setting up the workbench
*/
let created = false;
let workbenchPromiseResolve: Function;
const workbenchPromise = new Promise<IWorkbench>(resolve => workbenchPromiseResolve = resolve);
async function create(domElement: HTMLElement, options: IWorkbenchConstructionOptions): Promise<void> {
// Assert that the workbench is not created more than once. We currently
// do not support this and require a full context switch to clean-up.
if (created) {
throw new Error('Unable to create the VSCode workbench more than once.');
} else {
created = true;
}
// Startup workbench and resolve waiters
const workbench = await main(domElement, options);
workbenchPromiseResolve(workbench);
// Register commands if any
if (Array.isArray(options.commands)) {
for (const command of options.commands) {
CommandsRegistry.registerCommand(command.id, (accessor, ...args) => {
// we currently only pass on the arguments but not the accessor
// to the command to reduce our exposure of internal API.
return command.handler(...args);
});
}
}
}
//#region API Facade
namespace commands {
/**
* Allows to execute any command if known with the provided arguments.
*
* @param command Identifier of the command to execute.
* @param rest Parameters passed to the command function.
* @return A promise that resolves to the returned value of the given command.
*/
export async function executeCommand(command: string, ...args: any[]): Promise<unknown> {
const workbench = await workbenchPromise;
return workbench.commands.executeCommand(command, ...args);
}
}
export {
// Factory
create,
IWorkbenchConstructionOptions,
IWorkbench,
// Basic Types
URI,
UriComponents,
Event,
Emitter,
IDisposable,
Disposable,
// Workspace
IWorkspace,
IWorkspaceProvider,
// FileSystem
IFileSystemProvider,
FileSystemProviderCapabilities,
IFileChange,
FileChangeType,
// WebSockets
IWebSocketFactory,
IWebSocket,
// Resources
IResourceUriProvider,
// Credentials
ICredentialsProvider,
// Static Extensions
IStaticExtension,
IExtensionManifest,
// Callbacks
IURLCallbackProvider,
// LogLevel
LogLevel,
// Updates
IUpdateProvider,
IUpdate,
// Telemetry
ICommontTelemetryPropertiesResolver,
// External Uris
IExternalUriResolver,
// Tunnel
ITunnelProvider,
ITunnelFactory,
ITunnel,
ITunnelOptions,
// Ports
IShowPortCandidate,
// Commands
ICommand,
commands,
// Home Indicator
IHomeIndicator,
// Default layout
IDefaultEditor,
IDefaultLayout,
IDefaultPanelLayout,
IDefaultSideBarLayout,
};
//#endregion
|