Skip to content

Commit

Permalink
move renderer script and IPC into proposed and merge with general ren…
Browse files Browse the repository at this point in the history
…derer IPC, #123601
  • Loading branch information
jrieken committed May 31, 2021
1 parent da851ab commit 355df0e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 36 deletions.
68 changes: 38 additions & 30 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>;

//todo@API validate this works
asWebviewUri(localResource: Uri): Uri;
}

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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<T> {
/**
Expand Down Expand Up @@ -2499,15 +2474,48 @@ 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<boolean>;

//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`
* is set in its contribution.
*
* @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<TSend = any, TReceive = TSend>(rendererId: string): NotebookRendererMessaging<TSend, TReceive>;
}

Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};

Expand Down
11 changes: 7 additions & 4 deletions src/vs/workbench/api/common/extHostNotebookKernels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -185,18 +186,20 @@ export class ExtHostNotebookKernels implements ExtHostNotebookKernelsShape {
this._proxy.$removeKernel(handle);
}
},
// --- 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);
},
// --- priority
updateNotebookAffinity(notebook, priority) {
that._proxy.$updateNotebookPriority(handle, notebook.uri, priority);
}
};

this._kernelData.set(handle, {
Expand Down

0 comments on commit 355df0e

Please sign in to comment.