forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathworkbench.web.api.ts
825 lines (649 loc) · 19 KB
/
workbench.web.api.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
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
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
/*---------------------------------------------------------------------------------------------
* 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 { IWebSocketFactory, IWebSocket } from 'vs/platform/remote/browser/browserSocketFactory';
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, toDisposable } from 'vs/base/common/lifecycle';
import { IWorkspaceProvider, IWorkspace } from 'vs/workbench/services/host/browser/browserHostService';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { IProductConfiguration } from 'vs/base/common/product';
import { mark } from 'vs/base/common/performance';
import { ICredentialsProvider } from 'vs/workbench/services/credentials/common/credentials';
import { TunnelProviderFeatures } from 'vs/platform/remote/common/tunnel';
import { MenuId, MenuRegistry } from 'vs/platform/actions/common/actions';
import { DeferredPromise } from 'vs/base/common/async';
interface IResourceUriProvider {
(uri: URI): URI;
}
/**
* The identifier of an extension in the format: `PUBLISHER.NAME`.
* For example: `vscode.csharp`
*/
type ExtensionId = string;
interface ICommonTelemetryPropertiesResolver {
(): { [key: string]: any };
}
interface IExternalUriResolver {
(uri: URI): Promise<URI>;
}
/**
* External URL opener
*/
interface IExternalURLOpener {
/**
* Overrides the behavior when an external URL is about to be opened.
* Returning false means that the URL wasn't handled, and the default
* handling behavior should be used: `window.open(href, '_blank', 'noopener');`
*
* @returns true if URL was handled, false otherwise.
*/
openExternal(href: string): boolean | Promise<boolean>;
}
interface ITunnelProvider {
/**
* Support for creating tunnels.
*/
tunnelFactory?: ITunnelFactory;
/**
* Support for filtering candidate ports.
*/
showPortCandidate?: IShowPortCandidate;
/**
* The features that the tunnel provider supports.
*/
features?: TunnelProviderFeatures;
}
interface ITunnelFactory {
(tunnelOptions: ITunnelOptions, tunnelCreationOptions: TunnelCreationOptions): 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;
/**
* @deprecated Use privacy instead
*/
public?: boolean;
privacy?: string;
protocol?: string;
}
interface TunnelCreationOptions {
/**
* True when the local operating system will require elevation to use the requested local port.
*/
elevationRequired?: boolean;
}
interface ITunnel {
remoteAddress: { port: number, host: string };
/**
* The complete local address(ex. localhost:1234)
*/
localAddress: string;
/**
* @deprecated Use privacy instead
*/
public?: boolean;
privacy?: string;
/**
* If protocol is not provided, it is assumed to be http, regardless of the localAddress
*/
protocol?: string;
/**
* Implementers of Tunnel should fire onDidDispose when dispose is called.
*/
onDidDispose: Event<void>;
dispose(): Promise<void> | 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,
/**
* The optional label of the command. If provided, the command will appear
* in the command palette.
*/
label?: 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;
/**
* The icon name for the home indicator. This needs to be one of the existing
* icons from our Codicon icon set. For example `code`.
*/
icon: string;
/**
* A tooltip that will appear while hovering over the home indicator.
*/
title: string;
}
interface IWelcomeBanner {
/**
* Welcome banner message to appear as text.
*/
message: string;
/**
* Optional icon for the banner. This is either the URL to an icon to use
* or the name of one of the existing icons from our Codicon icon set.
*
* If not provided a default icon will be used.
*/
icon?: string | UriComponents;
/**
* Optional actions to appear as links after the welcome banner message.
*/
actions?: IWelcomeBannerAction[];
}
interface IWelcomeBannerAction {
/**
* The link to open when clicking. Supports command invocation when
* using the `command:<commandId>` value.
*/
href: string;
/**
* The label to show for the action link.
*/
label: string;
/**
* A tooltip that will appear while hovering over the action link.
*/
title?: string;
}
interface IWindowIndicator {
/**
* Triggering this event will cause the window indicator to update.
*/
readonly onDidChange?: Event<void>;
/**
* Label of the window indicator may include octicons
* e.g. `$(remote) label`
*/
label: string;
/**
* Tooltip of the window indicator should not include
* octicons and be descriptive.
*/
tooltip: string;
/**
* If provided, overrides the default command that
* is executed when clicking on the window indicator.
*/
command?: string;
}
enum ColorScheme {
DARK = 'dark',
LIGHT = 'light',
HIGH_CONTRAST = 'hc'
}
interface IInitialColorTheme {
/**
* Initial color theme type.
*/
readonly themeType: ColorScheme;
/**
* A list of workbench colors to apply initially.
*/
readonly colors?: { [colorId: string]: string };
}
interface IDefaultView {
readonly id: string;
}
interface IPosition {
readonly line: number;
readonly column: number;
}
interface IRange {
/**
* The start position. It is before or equal to end position.
*/
readonly start: IPosition;
/**
* The end position. It is after or equal to start position.
*/
readonly end: IPosition;
}
interface IDefaultEditor {
readonly uri: UriComponents;
readonly selection?: IRange;
readonly openOnlyIfExists?: boolean;
readonly openWith?: string;
}
interface IDefaultLayout {
readonly views?: IDefaultView[];
readonly editors?: IDefaultEditor[];
/**
* Forces this layout to be applied even if this isn't
* the first time the workspace has been opened
*/
readonly force?: boolean;
}
interface IProductQualityChangeHandler {
/**
* Handler is being called when the user wants to switch between
* `insider` or `stable` product qualities.
*/
(newQuality: 'insider' | 'stable'): void;
}
/**
* Settings sync options
*/
interface ISettingsSyncOptions {
/**
* Is settings sync enabled
*/
readonly enabled: boolean;
/**
* Version of extensions sync state.
* Extensions sync state will be reset if version is provided and different from previous version.
*/
readonly extensionsSyncStateVersion?: string;
/**
* Handler is being called when the user changes Settings Sync enablement.
*/
enablementHandler?(enablement: boolean): void;
}
interface IWorkbenchConstructionOptions {
//#region @coder
/**
* Path to the user data directory.
*/
readonly userDataPath?: string
//#endregion
//#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;
/**
* An URL pointing to the web worker extension host <iframe> src.
* @deprecated. This will be removed soon.
*/
readonly webWorkerExtensionHostIframeSrc?: 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;
/**
* Endpoints to be used for proxying authentication code exchange calls in the browser.
*/
readonly codeExchangeProxyEndpoints?: { [providerId: string]: string }
//#endregion
//#region Workbench configuration
/**
* A handler for opening workspaces and providing the initial workspace.
*/
readonly workspaceProvider?: IWorkspaceProvider;
/**
* Settings sync options
*/
readonly settingsSyncOptions?: ISettingsSyncOptions;
/**
* The credentials provider to store and retrieve secrets.
*/
readonly credentialsProvider?: ICredentialsProvider;
/**
* Additional builtin extensions that cannot be uninstalled but only be disabled.
* It can be one of the following:
* - `ExtensionId`: id of the extension that is available in Marketplace
* - `UriComponents`: location of the extension where it is hosted.
*/
readonly additionalBuiltinExtensions?: readonly (ExtensionId | UriComponents)[];
/**
* List of extensions to be enabled if they are installed.
* Note: This will not install extensions if not installed.
*/
readonly enabledExtensions?: readonly ExtensionId[];
/**
* [TEMPORARY]: This will be removed soon.
* Enable inlined extensions.
* Defaults to true.
*/
readonly _enableBuiltinExtensions?: boolean;
/**
* Additional domains allowed to open from the workbench without the
* link protection popup.
*/
readonly additionalTrustedDomains?: string[];
/**
* Urls that will be opened externally that are allowed access
* to the opener window. This is primarily used to allow
* `window.close()` to be called from the newly opened window.
*/
readonly openerAllowedExternalUrlPrefixes?: string[];
/**
* Support for URL callbacks.
*/
readonly urlCallbackProvider?: IURLCallbackProvider;
/**
* Support adding additional properties to telemetry.
*/
readonly resolveCommonTelemetryProperties?: ICommonTelemetryPropertiesResolver;
/**
* 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 default layout to apply on first time the workspace is opened (uness `force` is specified).
*/
readonly defaultLayout?: IDefaultLayout;
/**
* Optional configuration default overrides contributed to the workbench.
*/
readonly configurationDefaults?: Record<string, any>;
//#endregion
//#region Update/Quality related
/**
* Support for update reporting
*/
readonly updateProvider?: IUpdateProvider;
/**
* Support for product quality switching
*/
readonly productQualityChangeHandler?: IProductQualityChangeHandler;
//#endregion
//#region Branding
/**
* Optional home indicator to appear above the hamburger menu in the activity bar.
*/
readonly homeIndicator?: IHomeIndicator;
/**
* Optional welcome banner to appear above the workbench. Can be dismissed by the
* user.
*/
readonly welcomeBanner?: IWelcomeBanner;
/**
* Optional override for the product configuration properties.
*/
readonly productConfiguration?: Partial<IProductConfiguration>;
/**
* Optional override for properties of the window indicator in the status bar.
*/
readonly windowIndicator?: IWindowIndicator;
/**
* Specifies the default theme type (LIGHT, DARK..) and allows to provide initial colors that are shown
* until the color theme that is specified in the settings (`editor.colorTheme`) is loaded and applied.
* Once there are persisted colors from a last run these will be used.
*
* The idea is that the colors match the main colors from the theme defined in the `configurationDefaults`.
*/
readonly initialColorTheme?: IInitialColorTheme;
//#endregion
//#region Development options
readonly developmentOptions?: IDevelopmentOptions;
//#endregion
}
interface IDevelopmentOptions {
/**
* Current logging level. Default is `LogLevel.Info`.
*/
readonly logLevel?: LogLevel;
/**
* Location of a module containing extension tests to run once the workbench is open.
*/
readonly extensionTestsPath?: UriComponents;
/**
* Add extensions under development.
*/
readonly extensions?: readonly UriComponents[];
/**
* Whether to enable the smoke test driver.
*/
readonly enableSmokeTestDriver?: boolean;
}
interface IPerformanceMark {
/**
* The name of a performace marker.
*/
readonly name: string;
/**
* The UNIX timestamp at which the marker has been set.
*/
readonly startTime: number;
}
interface IWorkbench {
commands: {
/**
* @see [executeCommand](#commands.executeCommand)
*/
executeCommand(command: string, ...args: any[]): Promise<unknown>;
}
env: {
/**
* @see [getUriScheme](#env.getUriScheme)
*/
readonly uriScheme: string;
/**
* @see [retrievePerformanceMarks](#commands.retrievePerformanceMarks)
*/
retrievePerformanceMarks(): Promise<[string, readonly IPerformanceMark[]][]>;
/**
* @see [openUri](#env.openUri)
*/
openUri(target: URI): Promise<boolean>;
}
/**
* Triggers shutdown of the workbench programmatically. After this method is
* called, the workbench is not usable anymore and the page needs to reload
* or closed.
*
* This will also remove any `beforeUnload` handlers that would bring up a
* confirmation dialog.
*
* The returned promise should be awaited on to ensure any data to persist
* has been persisted.
*/
shutdown: () => Promise<void>;
}
/**
* 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;
const workbenchPromise = new DeferredPromise<IWorkbench>();
function create(domElement: HTMLElement, options: IWorkbenchConstructionOptions): IDisposable {
// Mark start of workbench
mark('code/didLoadWorkbenchMain');
// 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;
}
// Register commands if any
if (Array.isArray(options.commands)) {
for (const c of options.commands) {
const command: ICommand = c;
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);
});
// Commands with labels appear in the command palette
if (command.label) {
MenuRegistry.appendMenuItem(MenuId.CommandPalette, { command: { id: command.id, title: command.label } });
}
}
}
// Startup workbench and resolve waiters
let instantiatedWorkbench: IWorkbench | undefined = undefined;
main(domElement, options).then(workbench => {
instantiatedWorkbench = workbench;
workbenchPromise.complete(workbench);
});
return toDisposable(() => {
if (instantiatedWorkbench) {
instantiatedWorkbench.shutdown();
} else {
workbenchPromise.p.then(instantiatedWorkbench => instantiatedWorkbench.shutdown());
}
});
}
//#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.p;
return workbench.commands.executeCommand(command, ...args);
}
}
namespace env {
/**
* Retrieve performance marks that have been collected during startup. This function
* returns tuples of source and marks. A source is a dedicated context, like
* the renderer or an extension host.
*
* *Note* that marks can be collected on different machines and in different processes
* and that therefore "different clocks" are used. So, comparing `startTime`-properties
* across contexts should be taken with a grain of salt.
*
* @returns A promise that resolves to tuples of source and marks.
*/
export async function retrievePerformanceMarks(): Promise<[string, readonly IPerformanceMark[]][]> {
const workbench = await workbenchPromise.p;
return workbench.env.retrievePerformanceMarks();
}
/**
* @returns the scheme to use for opening the associated desktop
* experience via protocol handler.
*/
export async function getUriScheme(): Promise<string> {
const workbench = await workbenchPromise.p;
return workbench.env.uriScheme;
}
/**
* Allows to open a `URI` with the standard opener service of the
* workbench.
*/
export async function openUri(target: URI): Promise<boolean> {
const workbench = await workbenchPromise.p;
return workbench.env.openUri(target);
}
}
export {
// Factory
create,
IWorkbenchConstructionOptions,
IWorkbench,
// Basic Types
URI,
UriComponents,
Event,
Emitter,
IDisposable,
Disposable,
// Workspace
IWorkspace,
IWorkspaceProvider,
// WebSockets
IWebSocketFactory,
IWebSocket,
// Resources
IResourceUriProvider,
// Credentials
ICredentialsProvider,
// Callbacks
IURLCallbackProvider,
// LogLevel
LogLevel,
// SettingsSync
ISettingsSyncOptions,
// Updates/Quality
IUpdateProvider,
IUpdate,
IProductQualityChangeHandler,
// Telemetry
ICommonTelemetryPropertiesResolver,
// External Uris
IExternalUriResolver,
// External URL Opener
IExternalURLOpener,
// Tunnel
ITunnelProvider,
ITunnelFactory,
ITunnel,
ITunnelOptions,
// Ports
IShowPortCandidate,
// Commands
ICommand,
commands,
// Branding
IHomeIndicator,
IWelcomeBanner,
IWelcomeBannerAction,
IProductConfiguration,
IWindowIndicator,
IInitialColorTheme,
// Default layout
IDefaultView,
IDefaultEditor,
IDefaultLayout,
IPosition,
IRange as ISelection,
// Env
IPerformanceMark,
env,
// Development
IDevelopmentOptions
};
//#endregion