@@ -16,6 +16,7 @@ import { IUpdateProvider, IUpdate } from 'vs/workbench/services/update/browser/u
1616import { Event , Emitter } from 'vs/base/common/event' ;
1717import { Disposable , IDisposable } from 'vs/base/common/lifecycle' ;
1818import { IWorkspaceProvider , IWorkspace } from 'vs/workbench/services/host/browser/browserHostService' ;
19+ import { CommandsRegistry } from 'vs/platform/commands/common/commands' ;
1920
2021interface IResourceUriProvider {
2122 ( uri : URI ) : URI ;
@@ -36,18 +37,23 @@ interface IExternalUriResolver {
3637
3738interface TunnelOptions {
3839 remoteAddress : { port : number , host : string } ;
39- // The desired local port. If this port can't be used, then another will be chosen.
40+ /**
41+ * The desired local port. If this port can't be used, then another will be chosen.
42+ */
4043 localAddressPort ?: number ;
4144 label ?: string ;
4245}
4346
44- interface Tunnel {
47+ interface Tunnel extends IDisposable {
4548 remoteAddress : { port : number , host : string } ;
46- //The complete local address(ex. localhost:1234)
49+ /**
50+ * The complete local address(ex. localhost:1234)
51+ */
4752 localAddress : string ;
48- // Implementers of Tunnel should fire onDidDispose when dispose is called.
53+ /**
54+ * Implementers of Tunnel should fire onDidDispose when dispose is called.
55+ */
4956 onDidDispose : Event < void > ;
50- dispose ( ) : void ;
5157}
5258
5359interface ITunnelFactory {
@@ -186,14 +192,43 @@ interface IWorkbenchConstructionOptions {
186192 readonly driver ?: boolean ;
187193}
188194
195+ interface ICommandHandler {
196+ ( ...args : any [ ] ) : void ;
197+ }
198+
199+ interface IWorkbench {
200+
201+ /**
202+ * Register a command with the provided identifier and handler with
203+ * the workbench. The command can be called from extensions using the
204+ * `vscode.commands.executeCommand` API.
205+ */
206+ registerCommand ( id : string , command : ICommandHandler ) : IDisposable ;
207+ }
208+
189209/**
190210 * Creates the workbench with the provided options in the provided container.
191211 *
192212 * @param domElement the container to create the workbench in
193213 * @param options for setting up the workbench
214+ *
215+ * @returns the workbench facade with additional methods to call on.
194216 */
195- function create ( domElement : HTMLElement , options : IWorkbenchConstructionOptions ) : Promise < void > {
196- return main ( domElement , options ) ;
217+ async function create ( domElement : HTMLElement , options : IWorkbenchConstructionOptions ) : Promise < IWorkbench > {
218+
219+ // Startup workbench
220+ await main ( domElement , options ) ;
221+
222+ // Return facade
223+ return {
224+ registerCommand : ( id : string , command : ICommandHandler ) : IDisposable => {
225+ return CommandsRegistry . registerCommand ( id , ( accessor , ...args : any [ ] ) => {
226+ // we currently only pass on the arguments but not the accessor
227+ // to the command to reduce our exposure of internal API.
228+ command ( ...args ) ;
229+ } ) ;
230+ }
231+ } ;
197232}
198233
199234export {
@@ -202,6 +237,10 @@ export {
202237 create ,
203238 IWorkbenchConstructionOptions ,
204239
240+ // Workbench Facade
241+ IWorkbench ,
242+ ICommandHandler ,
243+
205244 // Basic Types
206245 URI ,
207246 UriComponents ,
0 commit comments