Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/workbench/browser/web.api.ts
3294 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import type { PerformanceMark } from '../../base/common/performance.js';
7
import type { UriComponents, URI } from '../../base/common/uri.js';
8
import type { IWebSocketFactory } from '../../platform/remote/browser/browserSocketFactory.js';
9
import type { IURLCallbackProvider } from '../services/url/browser/urlService.js';
10
import type { LogLevel } from '../../platform/log/common/log.js';
11
import type { IUpdateProvider } from '../services/update/browser/updateService.js';
12
import type { Event } from '../../base/common/event.js';
13
import type { IProductConfiguration } from '../../base/common/product.js';
14
import type { ISecretStorageProvider } from '../../platform/secrets/common/secrets.js';
15
import type { TunnelProviderFeatures } from '../../platform/tunnel/common/tunnel.js';
16
import type { IProgress, IProgressCompositeOptions, IProgressDialogOptions, IProgressNotificationOptions, IProgressOptions, IProgressStep, IProgressWindowOptions } from '../../platform/progress/common/progress.js';
17
import type { ITextEditorOptions } from '../../platform/editor/common/editor.js';
18
import type { IFolderToOpen, IWorkspaceToOpen } from '../../platform/window/common/window.js';
19
import type { EditorGroupLayout } from '../services/editor/common/editorGroupsService.js';
20
import type { IEmbedderTerminalOptions } from '../services/terminal/common/embedderTerminalService.js';
21
import type { IAuthenticationProvider } from '../services/authentication/common/authentication.js';
22
23
/**
24
* The `IWorkbench` interface is the API facade for web embedders
25
* to call into the workbench.
26
*
27
* Note: Changes to this interface need to be announced and adopted.
28
*/
29
export interface IWorkbench {
30
31
commands: {
32
33
/**
34
* Allows to execute any command if known with the provided arguments.
35
*
36
* @param command Identifier of the command to execute.
37
* @param rest Parameters passed to the command function.
38
* @return A promise that resolves to the returned value of the given command.
39
*/
40
executeCommand(command: string, ...args: any[]): Promise<unknown>;
41
};
42
43
logger: {
44
45
/**
46
* Logging for embedder.
47
*
48
* @param level The log level of the message to be printed.
49
* @param message Message to be printed.
50
*/
51
log(level: LogLevel, message: string): void;
52
};
53
54
env: {
55
56
/**
57
* @returns the scheme to use for opening the associated desktop
58
* experience via protocol handler.
59
*/
60
getUriScheme(): Promise<string>;
61
62
/**
63
* Retrieve performance marks that have been collected during startup. This function
64
* returns tuples of source and marks. A source is a dedicated context, like
65
* the renderer or an extension host.
66
*
67
* *Note* that marks can be collected on different machines and in different processes
68
* and that therefore "different clocks" are used. So, comparing `startTime`-properties
69
* across contexts should be taken with a grain of salt.
70
*
71
* @returns A promise that resolves to tuples of source and marks.
72
*/
73
retrievePerformanceMarks(): Promise<[string, readonly PerformanceMark[]][]>;
74
75
/**
76
* Allows to open a target Uri with the standard opener service of the
77
* workbench.
78
*/
79
openUri(target: URI | UriComponents): Promise<boolean>;
80
};
81
82
window: {
83
84
/**
85
* Show progress in the editor. Progress is shown while running the given callback
86
* and while the promise it returned isn't resolved nor rejected.
87
*
88
* @param task A callback returning a promise.
89
* @return A promise that resolves to the returned value of the given task result.
90
*/
91
withProgress<R>(
92
options: IProgressOptions | IProgressDialogOptions | IProgressNotificationOptions | IProgressWindowOptions | IProgressCompositeOptions,
93
task: (progress: IProgress<IProgressStep>) => Promise<R>
94
): Promise<R>;
95
96
/**
97
* Creates a terminal with limited capabilities that is intended for
98
* writing output from the embedder before the workbench has finished
99
* loading. When an embedder terminal is created it will automatically
100
* show to the user.
101
*
102
* @param options The definition of the terminal, this is similar to
103
* `ExtensionTerminalOptions` in the extension API.
104
*/
105
createTerminal(options: IEmbedderTerminalOptions): Promise<void>;
106
107
/**
108
* Show an information message to users. Optionally provide an array of items which will be presented as
109
* clickable buttons.
110
*
111
* @param message The message to show.
112
* @param items A set of items that will be rendered as actions in the message.
113
* @returns A thenable that resolves to the selected item or `undefined` when being dismissed.
114
*/
115
showInformationMessage<T extends string>(message: string, ...items: T[]): Promise<T | undefined>;
116
};
117
118
workspace: {
119
/**
120
* Resolves once the remote authority has been resolved.
121
*/
122
didResolveRemoteAuthority(): Promise<void>;
123
124
/**
125
* Forwards a port. If the current embedder implements a tunnelFactory then that will be used to make the tunnel.
126
* By default, openTunnel only support localhost; however, a tunnelFactory can be used to support other ips.
127
*
128
* @throws When run in an environment without a remote.
129
*
130
* @param tunnelOptions The `localPort` is a suggestion only. If that port is not available another will be chosen.
131
*/
132
openTunnel(tunnelOptions: ITunnelOptions): Promise<ITunnel>;
133
};
134
135
/**
136
* Triggers shutdown of the workbench programmatically. After this method is
137
* called, the workbench is not usable anymore and the page needs to reload
138
* or closed.
139
*
140
* This will also remove any `beforeUnload` handlers that would bring up a
141
* confirmation dialog.
142
*
143
* The returned promise should be awaited on to ensure any data to persist
144
* has been persisted.
145
*/
146
shutdown: () => Promise<void>;
147
}
148
149
export interface IWorkbenchConstructionOptions {
150
151
//#region Connection related configuration
152
153
/**
154
* The remote authority is the IP:PORT from where the workbench is served
155
* from. It is for example being used for the websocket connections as address.
156
*/
157
readonly remoteAuthority?: string;
158
159
/**
160
* The server base path is the path where the workbench is served from.
161
* The path must be absolute (start with a slash).
162
* Corresponds to option `server-base-path` on the server side.
163
*/
164
readonly serverBasePath?: string;
165
166
/**
167
* The connection token to send to the server.
168
*/
169
readonly connectionToken?: string | Promise<string>;
170
171
/**
172
* An endpoint to serve iframe content ("webview") from. This is required
173
* to provide full security isolation from the workbench host.
174
*/
175
readonly webviewEndpoint?: string;
176
177
/**
178
* A factory for web sockets.
179
*/
180
readonly webSocketFactory?: IWebSocketFactory;
181
182
/**
183
* A provider for resource URIs.
184
*
185
* *Note*: This will only be invoked after the `connectionToken` is resolved.
186
*/
187
readonly resourceUriProvider?: IResourceUriProvider;
188
189
/**
190
* Resolves an external uri before it is opened.
191
*/
192
readonly resolveExternalUri?: IExternalUriResolver;
193
194
/**
195
* A provider for supplying tunneling functionality,
196
* such as creating tunnels and showing candidate ports to forward.
197
*/
198
readonly tunnelProvider?: ITunnelProvider;
199
200
/**
201
* Endpoints to be used for proxying authentication code exchange calls in the browser.
202
*/
203
readonly codeExchangeProxyEndpoints?: { [providerId: string]: string };
204
205
/**
206
* The identifier of an edit session associated with the current workspace.
207
*/
208
readonly editSessionId?: string;
209
210
/**
211
* Resource delegation handler that allows for loading of resources when
212
* using remote resolvers.
213
*
214
* This is exclusive with {@link resourceUriProvider}. `resourceUriProvider`
215
* should be used if a {@link webSocketFactory} is used, and will be preferred.
216
*/
217
readonly remoteResourceProvider?: IRemoteResourceProvider;
218
219
//#endregion
220
221
222
//#region Workbench configuration
223
224
/**
225
* A handler for opening workspaces and providing the initial workspace.
226
*/
227
readonly workspaceProvider?: IWorkspaceProvider;
228
229
/**
230
* Settings sync options
231
*/
232
readonly settingsSyncOptions?: ISettingsSyncOptions;
233
234
/**
235
* The secret storage provider to store and retrieve secrets.
236
*/
237
readonly secretStorageProvider?: ISecretStorageProvider;
238
239
/**
240
* Additional builtin extensions those cannot be uninstalled but only be disabled.
241
* It can be one of the following:
242
* - an extension in the Marketplace
243
* - location of the extension where it is hosted.
244
*/
245
readonly additionalBuiltinExtensions?: readonly (MarketplaceExtension | UriComponents)[];
246
247
/**
248
* List of extensions to be enabled if they are installed.
249
* Note: This will not install extensions if not installed.
250
*/
251
readonly enabledExtensions?: readonly ExtensionId[];
252
253
/**
254
* Additional domains allowed to open from the workbench without the
255
* link protection popup.
256
*/
257
readonly additionalTrustedDomains?: string[];
258
259
/**
260
* Enable workspace trust feature for the current window
261
*/
262
readonly enableWorkspaceTrust?: boolean;
263
264
/**
265
* Urls that will be opened externally that are allowed access
266
* to the opener window. This is primarily used to allow
267
* `window.close()` to be called from the newly opened window.
268
*/
269
readonly openerAllowedExternalUrlPrefixes?: string[];
270
271
/**
272
* Support for URL callbacks.
273
*/
274
readonly urlCallbackProvider?: IURLCallbackProvider;
275
276
/**
277
* Support adding additional properties to telemetry.
278
*/
279
readonly resolveCommonTelemetryProperties?: ICommonTelemetryPropertiesResolver;
280
281
/**
282
* A set of optional commands that should be registered with the commands
283
* registry.
284
*
285
* Note: commands can be called from extensions if the identifier is known!
286
*/
287
readonly commands?: readonly ICommand[];
288
289
/**
290
* Optional default layout to apply on first time the workspace is opened
291
* (unless `force` is specified). This includes visibility of views and
292
* editors including editor grid layout.
293
*/
294
readonly defaultLayout?: IDefaultLayout;
295
296
/**
297
* Optional configuration default overrides contributed to the workbench.
298
*/
299
readonly configurationDefaults?: Record<string, any>;
300
301
//#endregion
302
303
//#region Profile options
304
305
/**
306
* Profile to use for the workbench.
307
*/
308
readonly profile?: { readonly name: string; readonly contents?: string | UriComponents };
309
310
/**
311
* URI of the profile to preview.
312
*/
313
readonly profileToPreview?: UriComponents;
314
315
//#endregion
316
317
318
//#region Update/Quality related
319
320
/**
321
* Support for update reporting
322
*/
323
readonly updateProvider?: IUpdateProvider;
324
325
/**
326
* Support for product quality switching
327
*/
328
readonly productQualityChangeHandler?: IProductQualityChangeHandler;
329
330
//#endregion
331
332
333
//#region Branding
334
335
/**
336
* Optional welcome banner to appear above the workbench. Can be dismissed by the
337
* user.
338
*/
339
readonly welcomeBanner?: IWelcomeBanner;
340
341
/**
342
* Optional override for the product configuration properties.
343
*/
344
readonly productConfiguration?: Partial<IProductConfiguration>;
345
346
/**
347
* Optional override for properties of the window indicator in the status bar.
348
*/
349
readonly windowIndicator?: IWindowIndicator;
350
351
/**
352
* Specifies the default theme type (LIGHT, DARK..) and allows to provide initial colors that are shown
353
* until the color theme that is specified in the settings (`editor.colorTheme`) is loaded and applied.
354
* Once there are persisted colors from a last run these will be used.
355
*
356
* The idea is that the colors match the main colors from the theme defined in the `configurationDefaults`.
357
*/
358
readonly initialColorTheme?: IInitialColorTheme;
359
360
//#endregion
361
362
363
//#region IPC
364
365
readonly messagePorts?: ReadonlyMap<ExtensionId, MessagePort>;
366
367
//#endregion
368
369
//#region Authentication Providers
370
371
/**
372
* Optional authentication provider contributions. These take precedence over
373
* any authentication providers contributed via extensions.
374
*/
375
readonly authenticationProviders?: readonly IAuthenticationProvider[];
376
377
//#endregion
378
379
//#region Development options
380
381
readonly developmentOptions?: IDevelopmentOptions;
382
383
//#endregion
384
385
}
386
387
388
/**
389
* A workspace to open in the workbench can either be:
390
* - a workspace file with 0-N folders (via `workspaceUri`)
391
* - a single folder (via `folderUri`)
392
* - empty (via `undefined`)
393
*/
394
export type IWorkspace = IWorkspaceToOpen | IFolderToOpen | undefined;
395
396
export interface IWorkspaceProvider {
397
398
/**
399
* The initial workspace to open.
400
*/
401
readonly workspace: IWorkspace;
402
403
/**
404
* Arbitrary payload from the `IWorkspaceProvider.open` call.
405
*/
406
readonly payload?: object;
407
408
/**
409
* Return `true` if the provided [workspace](#IWorkspaceProvider.workspace) is trusted, `false` if not trusted, `undefined` if unknown.
410
*/
411
readonly trusted: boolean | undefined;
412
413
/**
414
* Asks to open a workspace in the current or a new window.
415
*
416
* @param workspace the workspace to open.
417
* @param options optional options for the workspace to open.
418
* - `reuse`: whether to open inside the current window or a new window
419
* - `payload`: arbitrary payload that should be made available
420
* to the opening window via the `IWorkspaceProvider.payload` property.
421
* @param payload optional payload to send to the workspace to open.
422
*
423
* @returns true if successfully opened, false otherwise.
424
*/
425
open(workspace: IWorkspace, options?: { reuse?: boolean; payload?: object }): Promise<boolean>;
426
}
427
428
export interface IResourceUriProvider {
429
(uri: URI): URI;
430
}
431
432
/**
433
* The identifier of an extension in the format: `PUBLISHER.NAME`. For example: `vscode.csharp`
434
*/
435
export type ExtensionId = string;
436
437
export type MarketplaceExtension = ExtensionId | { readonly id: ExtensionId; preRelease?: boolean; migrateStorageFrom?: ExtensionId };
438
439
export interface ICommonTelemetryPropertiesResolver {
440
(): { [key: string]: any };
441
}
442
443
export interface IExternalUriResolver {
444
(uri: URI): Promise<URI>;
445
}
446
447
export interface IExternalURLOpener {
448
449
/**
450
* Overrides the behavior when an external URL is about to be opened.
451
* Returning false means that the URL wasn't handled, and the default
452
* handling behavior should be used: `window.open(href, '_blank', 'noopener');`
453
*
454
* @returns true if URL was handled, false otherwise.
455
*/
456
openExternal(href: string): boolean | Promise<boolean>;
457
}
458
459
export interface ITunnelProvider {
460
461
/**
462
* Support for creating tunnels.
463
*/
464
tunnelFactory?: ITunnelFactory;
465
466
/**
467
* Support for filtering candidate ports.
468
*/
469
showPortCandidate?: IShowPortCandidate;
470
471
/**
472
* The features that the tunnel provider supports.
473
*/
474
features?: TunnelProviderFeatures;
475
}
476
477
export interface ITunnelFactory {
478
(tunnelOptions: ITunnelOptions, tunnelCreationOptions: TunnelCreationOptions): Promise<ITunnel> | undefined;
479
}
480
481
export interface ITunnelOptions {
482
483
remoteAddress: { port: number; host: string };
484
485
/**
486
* The desired local port. If this port can't be used, then another will be chosen.
487
*/
488
localAddressPort?: number;
489
490
label?: string;
491
492
privacy?: string;
493
494
protocol?: string;
495
}
496
497
export interface TunnelCreationOptions {
498
499
/**
500
* True when the local operating system will require elevation to use the requested local port.
501
*/
502
elevationRequired?: boolean;
503
}
504
505
export interface ITunnel {
506
507
remoteAddress: { port: number; host: string };
508
509
/**
510
* The complete local address(ex. localhost:1234)
511
*/
512
localAddress: string;
513
514
privacy?: string;
515
516
/**
517
* If protocol is not provided, it is assumed to be http, regardless of the localAddress
518
*/
519
protocol?: string;
520
521
/**
522
* Implementers of Tunnel should fire onDidDispose when dispose is called.
523
*/
524
onDidDispose: Event<void>;
525
526
dispose(): Promise<void> | void;
527
}
528
529
export interface IShowPortCandidate {
530
(host: string, port: number, detail: string): Promise<boolean>;
531
}
532
533
export enum Menu {
534
CommandPalette,
535
StatusBarWindowIndicatorMenu,
536
}
537
538
export interface ICommand {
539
540
/**
541
* An identifier for the command. Commands can be executed from extensions
542
* using the `vscode.commands.executeCommand` API using that command ID.
543
*/
544
id: string;
545
546
/**
547
* The optional label of the command. If provided, the command will appear
548
* in the command palette.
549
*/
550
label?: string;
551
552
/**
553
* The optional menus to append this command to. Only valid if `label` is
554
* provided as well.
555
* @default Menu.CommandPalette
556
*/
557
menu?: Menu | Menu[];
558
559
/**
560
* A function that is being executed with any arguments passed over. The
561
* return type will be send back to the caller.
562
*
563
* Note: arguments and return type should be serializable so that they can
564
* be exchanged across processes boundaries.
565
*/
566
handler: (...args: any[]) => unknown;
567
}
568
569
export interface IWelcomeBanner {
570
571
/**
572
* Welcome banner message to appear as text.
573
*/
574
message: string;
575
576
/**
577
* Optional icon for the banner. This is either the URL to an icon to use
578
* or the name of one of the existing icons from our Codicon icon set.
579
*
580
* If not provided a default icon will be used.
581
*/
582
icon?: string | UriComponents;
583
584
/**
585
* Optional actions to appear as links after the welcome banner message.
586
*/
587
actions?: IWelcomeLinkAction[];
588
}
589
590
export interface IWelcomeLinkAction {
591
592
/**
593
* The link to open when clicking. Supports command invocation when
594
* using the `command:<commandId>` value.
595
*/
596
href: string;
597
598
/**
599
* The label to show for the action link.
600
*/
601
label: string;
602
603
/**
604
* A tooltip that will appear while hovering over the action link.
605
*/
606
title?: string;
607
}
608
609
export interface IWindowIndicator {
610
611
/**
612
* Triggering this event will cause the window indicator to update.
613
*/
614
readonly onDidChange?: Event<void>;
615
616
/**
617
* Label of the window indicator may include octicons
618
* e.g. `$(remote) label`
619
*/
620
label: string;
621
622
/**
623
* Tooltip of the window indicator should not include
624
* octicons and be descriptive.
625
*/
626
tooltip: string;
627
628
/**
629
* If provided, overrides the default command that
630
* is executed when clicking on the window indicator.
631
*/
632
command?: string;
633
}
634
635
export enum ColorScheme {
636
DARK = 'dark',
637
LIGHT = 'light',
638
HIGH_CONTRAST_LIGHT = 'hcLight',
639
HIGH_CONTRAST_DARK = 'hcDark'
640
}
641
642
export interface IInitialColorTheme {
643
644
/**
645
* Initial color theme type.
646
*/
647
readonly themeType: ColorScheme;
648
649
/**
650
* A list of workbench colors to apply initially.
651
*/
652
readonly colors?: { [colorId: string]: string };
653
}
654
655
export interface IDefaultView {
656
657
/**
658
* The identifier of the view to show by default.
659
*/
660
readonly id: string;
661
}
662
663
export interface IDefaultEditor {
664
665
/**
666
* The location of the editor in the editor grid layout.
667
* Editors are layed out in editor groups and the view
668
* column is counted from top left to bottom right in
669
* the order of appearance beginning with `1`.
670
*
671
* If not provided, the editor will open in the active
672
* group.
673
*/
674
readonly viewColumn?: number;
675
676
/**
677
* The resource of the editor to open.
678
*/
679
readonly uri: UriComponents;
680
681
/**
682
* Optional extra options like which editor
683
* to use or which text to select.
684
*/
685
readonly options?: ITextEditorOptions;
686
687
/**
688
* Will not open an untitled editor in case
689
* the resource does not exist.
690
*/
691
readonly openOnlyIfExists?: boolean;
692
}
693
694
export interface IDefaultLayout {
695
696
/**
697
* A list of views to show by default.
698
*/
699
readonly views?: IDefaultView[];
700
701
/**
702
* A list of editors to show by default.
703
*/
704
readonly editors?: IDefaultEditor[];
705
706
/**
707
* The layout to use for the workbench.
708
*/
709
readonly layout?: {
710
711
/**
712
* The layout of the editor area.
713
*/
714
readonly editors?: EditorGroupLayout;
715
};
716
717
/**
718
* Forces this layout to be applied even if this isn't
719
* the first time the workspace has been opened
720
*/
721
readonly force?: boolean;
722
}
723
724
export interface IProductQualityChangeHandler {
725
726
/**
727
* Handler is being called when the user wants to switch between
728
* `insider` or `stable` product qualities.
729
*/
730
(newQuality: 'insider' | 'stable'): void;
731
}
732
733
/**
734
* Settings sync options
735
*/
736
export interface ISettingsSyncOptions {
737
738
/**
739
* Is settings sync enabled
740
*/
741
readonly enabled: boolean;
742
743
/**
744
* Version of extensions sync state.
745
* Extensions sync state will be reset if version is provided and different from previous version.
746
*/
747
readonly extensionsSyncStateVersion?: string;
748
749
/**
750
* Handler is being called when the user changes Settings Sync enablement.
751
*/
752
enablementHandler?(enablement: boolean, authenticationProvider: string): void;
753
754
/**
755
* Authentication provider
756
*/
757
readonly authenticationProvider?: {
758
759
/**
760
* Unique identifier of the authentication provider.
761
*/
762
readonly id: string;
763
764
/**
765
* Called when the user wants to signin to Settings Sync using the given authentication provider.
766
* The returned promise should resolve to the authentication session id.
767
*/
768
signIn(): Promise<string>;
769
};
770
}
771
772
export interface IDevelopmentOptions {
773
774
/**
775
* Current logging level. Default is `LogLevel.Info`.
776
*/
777
readonly logLevel?: LogLevel;
778
779
/**
780
* Extension log level.
781
*/
782
readonly extensionLogLevel?: [string, LogLevel][];
783
784
/**
785
* Location of a module containing extension tests to run once the workbench is open.
786
*/
787
readonly extensionTestsPath?: UriComponents;
788
789
/**
790
* Add extensions under development.
791
*/
792
readonly extensions?: readonly UriComponents[];
793
794
/**
795
* Whether to enable the smoke test driver.
796
*/
797
readonly enableSmokeTestDriver?: boolean;
798
}
799
800
/**
801
* Utility provided in the {@link WorkbenchOptions} which allows loading resources
802
* when remote resolvers are used in the web.
803
*/
804
export interface IRemoteResourceProvider {
805
806
/**
807
* Path the workbench should delegate requests to. The embedder should
808
* install a service worker on this path and emit {@link onDidReceiveRequest}
809
* events when requests come in for that path.
810
*/
811
readonly path: string;
812
813
/**
814
* Event that should fire when requests are made on the {@link pathPrefix}.
815
*/
816
readonly onDidReceiveRequest: Event<IRemoteResourceRequest>;
817
}
818
819
/**
820
* todo@connor4312: this may eventually gain more properties like method and
821
* headers, but for now we only deal with GET requests.
822
*/
823
export interface IRemoteResourceRequest {
824
825
/**
826
* Request URI. Generally will begin with the current
827
* origin and {@link IRemoteResourceProvider.pathPrefix}.
828
*/
829
uri: URI;
830
831
/**
832
* A method called by the editor to issue a response to the request.
833
*/
834
respondWith(statusCode: number, body: Uint8Array, headers: Record<string, string>): void;
835
}
836
837