notebooks: pipe renderer API postmessages to the renderer itself (#100414)

* notebooks: pipe renderer API postmessages to the renderer itself

Previously the postMessage on acquireNotebookRenderer API was just
a proxy to the global vscode postmessage. Now, it's linked to the
renderer and will cause an optional `onDidReceiveMessage` method on
the renderer to be called.

The message still _also_ goes to the global webview message handling
for advanced use cases, but this change allows the webview<->renderer
communication to be more nicely contained
and separate for most use cases.

* wip

* fixup! pr comments
This commit is contained in:
Connor Peet
2020-06-22 09:35:16 -07:00
committed by GitHub
parent 5e6729d9bd
commit a57cb45be8
11 changed files with 206 additions and 85 deletions

View File

@@ -253,7 +253,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
return;
}
this._proxy.$acceptDocumentAndEditorsDelta(delta);
return this._proxy.$acceptDocumentAndEditorsDelta(delta);
}
registerListeners() {
@@ -476,16 +476,11 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
return this._proxy.$executeNotebook(viewType, uri, undefined, useAttachedKernel, token);
}
async $postMessage(handle: number, value: any): Promise<boolean> {
const activeEditorPane = this.editorService.activeEditorPane as any | undefined;
if (activeEditorPane?.isNotebookEditor) {
const notebookEditor = (activeEditorPane.getControl() as INotebookEditor);
if (notebookEditor.viewModel?.handle === handle) {
notebookEditor.postMessage(value);
return true;
}
async $postMessage(editorId: string, forRendererId: string | undefined, value: any): Promise<boolean> {
const editor = this._notebookService.getNotebookEditor(editorId) as INotebookEditor | undefined;
if (editor?.isNotebookEditor) {
editor.postMessage(forRendererId, value);
return true;
}
return false;
@@ -645,8 +640,8 @@ export class MainThreadNotebookController implements IMainNotebookController {
return this._mainThreadNotebook.executeNotebook(viewType, uri, useAttachedKernel, token);
}
onDidReceiveMessage(editorId: string, message: any): void {
this._proxy.$onDidReceiveMessage(editorId, message);
onDidReceiveMessage(editorId: string, rendererType: string | undefined, message: unknown): void {
this._proxy.$onDidReceiveMessage(editorId, rendererType, message);
}
async removeNotebookDocument(notebook: INotebookTextModel): Promise<void> {