From 355df0eccb67b2dd54e314c258405e523a8f3aaf Mon Sep 17 00:00:00 2001 From: Johannes Rieken Date: Mon, 31 May 2021 13:38:17 +0200 Subject: [PATCH] move renderer script and IPC into proposed and merge with general renderer IPC, https://github.com/microsoft/vscode/issues/123601 --- src/vs/vscode.proposed.d.ts | 68 +++++++++++-------- .../workbench/api/common/extHost.api.impl.ts | 4 +- .../api/common/extHostNotebookKernels.ts | 21 +++--- 3 files changed, 52 insertions(+), 41 deletions(-) diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index ddc97d00a53..61ea2c46f03 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1846,30 +1846,6 @@ declare module 'vscode' { * @returns A notebook cell execution. */ createNotebookCellExecution(cell: NotebookCell): NotebookCellExecution; - - // todo@API allow add, not remove - readonly rendererScripts: NotebookRendererScript[]; - - /** - * An event that fires when a {@link NotebookController.rendererScripts renderer script} has send a message to - * the controller. - */ - readonly onDidReceiveMessage: Event<{ editor: NotebookEditor, message: any }>; - - /** - * Send a message to the renderer of notebook editors. - * - * Note that only editors showing documents that are bound to this controller - * are receiving the message. - * - * @param message The message to send. - * @param editor A specific editor to send the message to. When `undefined` all applicable editors are receiving the message. - * @returns A promise that resolves to a boolean indicating if the message has been send or not. - */ - postMessage(message: any, editor?: NotebookEditor): Thenable; - - //todo@API validate this works - asWebviewUri(localResource: Uri): Uri; } /** @@ -2024,11 +2000,10 @@ declare module 'vscode' { * * @param id Identifier of the controller. Must be unique per extension. * @param viewType A notebook view type for which this controller is for. - * @param label The label of the controller - * @param handler - * @param rendererScripts todo@API should renderer scripts come later? + * @param label The label of the controller. + * @param handler The execute-handler of the controller. */ - export function createNotebookController(id: string, viewType: string, label: string, handler?: NotebookExecuteHandler, rendererScripts?: NotebookRendererScript[]): NotebookController; + export function createNotebookController(id: string, viewType: string, label: string, handler?: NotebookExecuteHandler): NotebookController; /** * Register a {@link NotebookCellStatusBarItemProvider cell statusbar item provider} for the given notebook type. @@ -2467,7 +2442,7 @@ declare module 'vscode' { //#endregion - //#region @connor4312 - notebook messaging: https://github.com/microsoft/vscode/issues/123601 + //#region @https://github.com/microsoft/vscode/issues/123601, notebook messaging export interface NotebookRendererMessage { /** @@ -2499,7 +2474,37 @@ declare module 'vscode' { postMessage(editor: NotebookEditor, message: TSend): void; } + export interface NotebookController { + + // todo@API allow add, not remove + readonly rendererScripts: NotebookRendererScript[]; + + /** + * An event that fires when a {@link NotebookController.rendererScripts renderer script} has send a message to + * the controller. + */ + readonly onDidReceiveMessage: Event<{ editor: NotebookEditor, message: any }>; + + /** + * Send a message to the renderer of notebook editors. + * + * Note that only editors showing documents that are bound to this controller + * are receiving the message. + * + * @param message The message to send. + * @param editor A specific editor to send the message to. When `undefined` all applicable editors are receiving the message. + * @returns A promise that resolves to a boolean indicating if the message has been send or not. + */ + postMessage(message: any, editor?: NotebookEditor): Thenable; + + //todo@API validate this works + asWebviewUri(localResource: Uri): Uri; + } + export namespace notebooks { + + export function createNotebookController(id: string, viewType: string, label: string, handler?: NotebookExecuteHandler, rendererScripts?: NotebookRendererScript[]): NotebookController; + /** * Creates a new messaging instance used to communicate with a specific * renderer. The renderer only has access to messaging if `requiresMessaging` @@ -2507,7 +2512,10 @@ declare module 'vscode' { * * @see https://github.com/microsoft/vscode/issues/123601 * @param rendererId The renderer ID to communicate with - */ + */ + // todo@API can ANY extension talk to renderer or is there a check that the calling extension + // declared the renderer in its package.json? + // todo@API align with vscode.Webview -> remove generics export function createRendererMessaging(rendererId: string): NotebookRendererMessaging; } diff --git a/src/vs/workbench/api/common/extHost.api.impl.ts b/src/vs/workbench/api/common/extHost.api.impl.ts index 3ba64de72d2..5e022597df8 100644 --- a/src/vs/workbench/api/common/extHost.api.impl.ts +++ b/src/vs/workbench/api/common/extHost.api.impl.ts @@ -1128,9 +1128,9 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I checkProposedApiEnabled(extension); return new ExtHostNotebookConcatDocument(extHostNotebook, extHostDocuments, notebook, selector); }, - createNotebookController(id, viewType, label, executeHandler, preloads) { + createNotebookController(id: string, viewType: string, label: string, handler?: vscode.NotebookExecuteHandler, rendererScripts?: vscode.NotebookRendererScript[]) { checkProposedApiEnabled(extension); - return extHostNotebookKernels.createNotebookController(extension, id, viewType, label, executeHandler, preloads); + return extHostNotebookKernels.createNotebookController(extension, id, viewType, label, handler, extension.enableProposedApi ? rendererScripts : undefined); } }; diff --git a/src/vs/workbench/api/common/extHostNotebookKernels.ts b/src/vs/workbench/api/common/extHostNotebookKernels.ts index b8f7d0fec73..a076d546cd0 100644 --- a/src/vs/workbench/api/common/extHostNotebookKernels.ts +++ b/src/vs/workbench/api/common/extHostNotebookKernels.ts @@ -21,6 +21,7 @@ import { CancellationTokenSource } from 'vs/base/common/cancellation'; import { asArray } from 'vs/base/common/arrays'; import { ILogService } from 'vs/platform/log/common/log'; import { NotebookCellOutput } from 'vs/workbench/api/common/extHostTypes'; +import { checkProposedApiEnabled } from 'vs/workbench/services/extensions/common/extensions'; interface IKernelData { extensionId: ExtensionIdentifier, @@ -185,18 +186,20 @@ export class ExtHostNotebookKernels implements ExtHostNotebookKernelsShape { this._proxy.$removeKernel(handle); } }, - // --- ipc - onDidReceiveMessage: onDidReceiveMessage.event, - postMessage(message, editor) { - return that._proxy.$postMessage(handle, editor && that._extHostNotebook.getIdByEditor(editor), message); - }, - asWebviewUri(uri: URI) { - return asWebviewUri(uri, that._initData.remote); - }, // --- priority updateNotebookAffinity(notebook, priority) { that._proxy.$updateNotebookPriority(handle, notebook.uri, priority); - } + }, + // --- ipc + onDidReceiveMessage: onDidReceiveMessage.event, + postMessage(message, editor) { + checkProposedApiEnabled(extension); + return that._proxy.$postMessage(handle, editor && that._extHostNotebook.getIdByEditor(editor), message); + }, + asWebviewUri(uri: URI) { + checkProposedApiEnabled(extension); + return asWebviewUri(uri, that._initData.remote); + }, }; this._kernelData.set(handle, {