Skip to content

Commit

Permalink
Update version & merge fix for IPyWidgets in Interactive window (#4209)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Dec 10, 2020
1 parent 4ad8959 commit 4bb5d16
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 24 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## 2020.12.1 (10 December 2020)

### Fixes

1. Fix support for IPyWidgets in Interactive Window.
([#4203](https://github.com/Microsoft/vscode-jupyter/issues/4203))

## 2020.12.0 (9 December 2020)

### Enhancements
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "jupyter",
"displayName": "Jupyter",
"version": "2020.12.0",
"version": "2020.12.1",
"description": "Jupyter notebook support, interactive programming and computing that supports Intellisense, debugging and more.",
"publisher": "ms-toolsai",
"enableProposedApi": true,
Expand Down
42 changes: 22 additions & 20 deletions src/client/datascience/ipywidgets/commonMessageCoordinator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ export class CommonMessageCoordinator {
this.jupyterOutput = this.serviceContainer.get<IOutputChannel>(IOutputChannel, JUPYTER_OUTPUT_CHANNEL);
}

public static async create(identity: Uri, serviceContainer: IServiceContainer): Promise<CommonMessageCoordinator> {
const result = new CommonMessageCoordinator(identity, serviceContainer);
await result.initialize();
return result;
public static create(identity: Uri, serviceContainer: IServiceContainer): CommonMessageCoordinator {
return new CommonMessageCoordinator(identity, serviceContainer);
}

public dispose() {
Expand Down Expand Up @@ -94,6 +92,19 @@ export class CommonMessageCoordinator {
this.getIPyWidgetScriptSource()?.onMessage(message, payload);
}

public async initialize() {
const dispatcher = this.getIPyWidgetMessageDispatcher();
const promises = [];
if (dispatcher) {
promises.push(dispatcher.initialize());
}
const scriptSource = this.getIPyWidgetScriptSource();
if (scriptSource) {
promises.push(scriptSource.initialize());
}
return Promise.all(promises);
}

private hash(s: string): string {
return this.hashFn().update(s).digest('hex');
}
Expand Down Expand Up @@ -164,6 +175,9 @@ export class CommonMessageCoordinator {
this.ipyWidgetMessageDispatcher = this.serviceContainer
.get<IPyWidgetMessageDispatcherFactory>(IPyWidgetMessageDispatcherFactory)
.create(this.identity);
this.disposables.push(
this.ipyWidgetMessageDispatcher.postMessage(this.postEmitter.fire.bind(this.postEmitter))
);
}
return this.ipyWidgetMessageDispatcher;
}
Expand All @@ -183,23 +197,11 @@ export class CommonMessageCoordinator {
this.serviceContainer.get<IPersistentStateFactory>(IPersistentStateFactory),
this.serviceContainer.get<IExtensionContext>(IExtensionContext)
);
this.disposables.push(this.ipyWidgetScriptSource.postMessage(this.postEmitter.fire.bind(this.postEmitter)));
this.disposables.push(
this.ipyWidgetScriptSource.postInternalMessage(this.postEmitter.fire.bind(this.postEmitter))
);
}
return this.ipyWidgetScriptSource;
}

private async initialize() {
const dispatcher = this.getIPyWidgetMessageDispatcher();
const promises = [];
if (dispatcher) {
this.disposables.push(dispatcher.postMessage(this.postEmitter.fire.bind(this.postEmitter)));
promises.push(dispatcher.initialize());
}
const scriptSource = this.getIPyWidgetScriptSource();
if (scriptSource) {
this.disposables.push(scriptSource.postMessage(this.postEmitter.fire.bind(this.postEmitter)));
this.disposables.push(scriptSource.postInternalMessage(this.postEmitter.fire.bind(this.postEmitter)));
promises.push(scriptSource.initialize());
}
return Promise.all(promises);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export class NotebookIPyWidgetCoordinator implements INotebookKernelResolver {
// entire VS code session, we have a map of notebook document to message coordinator
let promise = this.messageCoordinators.get(document.uri.toString());
if (!promise) {
promise = CommonMessageCoordinator.create(document.uri, this.serviceContainer);
const coordinator = CommonMessageCoordinator.create(document.uri, this.serviceContainer);
promise = coordinator.initialize().then(() => coordinator);
this.messageCoordinators.set(document.uri.toString(), promise);
}
return Cancellation.race(() => promise!.then(this.attachCoordinator.bind(this, document, webview)), token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class WebviewIPyWidgetCoordinator implements IInteractiveWindowListener {
// There should be an instance of the WebviewMessageCoordinator per notebook webview or interactive window. Create
// the message coordinator as soon as we're sure what notebook we're in.
this.notebookIdentity = args.resource;
this.messageCoordinator = await CommonMessageCoordinator.create(this.notebookIdentity, this.serviceContainer);
this.messageCoordinator = CommonMessageCoordinator.create(this.notebookIdentity, this.serviceContainer);
this.messageCoordinatorEvent = this.messageCoordinator.postMessage((e) => {
// Special case a specific message. It must be posted to the internal class, not the webview
if (e.message === InteractiveWindowMessages.ConvertUriForUseInWebViewRequest) {
Expand All @@ -71,5 +71,6 @@ export class WebviewIPyWidgetCoordinator implements IInteractiveWindowListener {
this.postEmitter.fire(e);
}
});
return this.messageCoordinator.initialize();
}
}

0 comments on commit 4bb5d16

Please sign in to comment.