Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
Expose the FileSystemProvider for big-dig:// to other VS Code extensi…
Browse files Browse the repository at this point in the history
…ons.

Summary:
This makes it so that the `FileSystemProvider` for the `big-dig` scheme can be
used by other extensions (providing a workaround for microsoft/vscode#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
  • Loading branch information
bolinfest authored and facebook-github-bot committed Aug 22, 2018
1 parent c1945d5 commit 8cf697a
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions modules/big-dig-vscode/src/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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());

Expand All @@ -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. */
Expand Down Expand Up @@ -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};
}

0 comments on commit 8cf697a

Please sign in to comment.