From 8cf697a04c76132f922bf19e27252990dbc83b41 Mon Sep 17 00:00:00 2001 From: Michael Bolin Date: Tue, 21 Aug 2018 22:47:35 -0700 Subject: [PATCH] Expose the FileSystemProvider for big-dig:// to other VS Code extensions. Summary: This makes it so that the `FileSystemProvider` for the `big-dig` scheme can be used by other extensions (providing a workaround for https://github.com/Microsoft/vscode/issues/48034). Here is an example of how to leverage this: ``` function getFileSystemProvider(): vscode.FileSystemProvider | null { const bigDig = vscode.extensions.getExtension("Facebook.big-dig-vscode"); if (bigDig == null) { return null; } if (!bigDig.isActive) { // Alternatively, make this method async and do: // return (await bigDig.activate()).fileSystemProvider; return null; } return bigDig.exports.fileSystemProvider; } ``` Note that this technique of making objects from the `big-dig-vscode` extension could be used more generally as the basis for a Big Dig client library so that other extensions can talk to Big Dig, as appropriate. One common case that has been discussed is language extensions reading from the user's `settings.json` to determine what sorts of extra arguments to add to the `initializationOptions`. Reviewed By: siegebell Differential Revision: D9419766 fbshipit-source-id: d705cc03f71b01e8cefead99a197f8b307c2ad5d --- modules/big-dig-vscode/src/extension.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/modules/big-dig-vscode/src/extension.js b/modules/big-dig-vscode/src/extension.js index f221ef2296..7893accb52 100644 --- a/modules/big-dig-vscode/src/extension.js +++ b/modules/big-dig-vscode/src/extension.js @@ -30,7 +30,11 @@ import {startDebugProviders} from './debugger'; import {BIG_DIG_SESSION, startCli} from './terminal/cli'; import {__DEV__} from './dev'; -export function activate(context: vscode.ExtensionContext) { +type ExtensionExports = { + fileSystemProvider: vscode.FileSystemProvider, +}; + +export function activate(context: vscode.ExtensionContext): ExtensionExports { if (__DEV__) { initServerDevelopmentDeployment(); } @@ -39,7 +43,8 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(startFilesystems()); - context.subscriptions.push(startMultiplexingFilesystems()); + const filesystems = startMultiplexingFilesystems(); + context.subscriptions.push(filesystems.disposable); context.subscriptions.push(startBigDigTomlServices()); @@ -50,6 +55,10 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(startDebugProviders()); context.subscriptions.push(startSearchProviders()); + + return { + fileSystemProvider: filesystems.fileSystemProvider, + }; } /** This function is called when this extension is deactivated. */ @@ -109,9 +118,13 @@ function loadCommands(context: vscode.ExtensionContext): void { * @return a disposable that unregisters the multiplexer and stops listening * for new filesystems. */ -function startMultiplexingFilesystems(): IDisposable { +function startMultiplexingFilesystems(): { + disposable: IDisposable, + fileSystemProvider: vscode.FileSystemProvider, +} { const fsMultiplexer = new FileSystemMultiplexer(); const sub = onEachFilesystem(fs => fsMultiplexer.addFileSystem(fs)); fsMultiplexer.register(); - return vscode.Disposable.from(sub, fsMultiplexer); + const disposable = vscode.Disposable.from(sub, fsMultiplexer); + return {disposable, fileSystemProvider: fsMultiplexer}; }