Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

notebooks: remove impure renderer API #105035

Merged
merged 1 commit into from
Aug 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions/vscode-notebook-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
{
"viewType": "notebookCoreTestRenderer",
"displayName": "Notebook Core Test Renderer",
"entrypoint": "./src/customRenderer.js",
"mimeTypes": [
"text/custom"
]
Expand Down
8 changes: 8 additions & 0 deletions extensions/vscode-notebook-tests/src/customRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ vscode.postMessage({
firstMessage: true
}
});

const notebook = acquireNotebookRendererApi('notebookCoreTestRenderer');

notebook.onDidCreateOutput(({ element, mimeType }) => {
const div = document.createElement('div');
div.innerText = `Hello ${mimeType}!`;
element.appendChild(div);
});
13 changes: 0 additions & 13 deletions extensions/vscode-notebook-tests/src/notebookTestMain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import * as vscode from 'vscode';
import * as path from 'path';
import { smokeTestActivate } from './notebookSmokeTestMain';

export function activate(context: vscode.ExtensionContext): any {
Expand Down Expand Up @@ -117,16 +116,4 @@ export function activate(context: vscode.ExtensionContext): any {
},
cancelCellExecution: async (_document: vscode.NotebookDocument, _cell: vscode.NotebookCell) => { }
}));

const preloadUri = vscode.Uri.file(path.resolve(__dirname, '../src/customRenderer.js'));
context.subscriptions.push(vscode.notebook.registerNotebookOutputRenderer('notebookCoreTestRenderer', {
mimeTypes: [
'text/custom'
]
}, {
preloads: [preloadUri],
render(_document: vscode.NotebookDocument, _request: vscode.NotebookRenderRequest): string {
return '<div>test</div>';
}
}));
}
31 changes: 0 additions & 31 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1436,31 +1436,6 @@ declare module 'vscode' {
outputId: string;
}

export interface NotebookOutputRenderer {
/**
*
* @returns HTML fragment. We can probably return `CellOutput` instead of string ?
*
*/
render(document: NotebookDocument, request: NotebookRenderRequest): string;

/**
* Call before HTML from the renderer is executed, and will be called for
* every editor associated with notebook documents where the renderer
* is or was used.
*
* The communication object will only send and receive messages to the
* render API, retrieved via `acquireNotebookRendererApi`, acquired with
* this specific renderer's ID.
*
* If you need to keep an association between the communication object
* and the document for use in the `render()` method, you can use a WeakMap.
*/
resolveNotebook?(document: NotebookDocument, communication: NotebookCommunication): void;

readonly preloads?: Uri[];
}

export interface NotebookCellsChangeData {
readonly start: number;
readonly deletedCount: number;
Expand Down Expand Up @@ -1679,12 +1654,6 @@ declare module 'vscode' {
kernel: NotebookKernel
): Disposable;

export function registerNotebookOutputRenderer(
id: string,
outputSelector: NotebookOutputSelector,
renderer: NotebookOutputRenderer
): Disposable;

export const onDidOpenNotebookDocument: Event<NotebookDocument>;
export const onDidCloseNotebookDocument: Event<NotebookDocument>;
export const onDidSaveNotebookDocument: Event<NotebookDocument>;
Expand Down
51 changes: 6 additions & 45 deletions src/vs/workbench/api/browser/mainThreadNotebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MainContext, MainThreadNotebookShape, NotebookExtensionDescription, IEx
import { Disposable, IDisposable, combinedDisposable, DisposableStore } from 'vs/base/common/lifecycle';
import { URI, UriComponents } from 'vs/base/common/uri';
import { INotebookService, IMainNotebookController } from 'vs/workbench/contrib/notebook/common/notebookService';
import { INotebookMimeTypeSelector, NOTEBOOK_DISPLAY_ORDER, NotebookCellOutputsSplice, NotebookDocumentMetadata, NotebookCellMetadata, ICellEditOperation, ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, CellEditType, CellKind, INotebookKernelInfo, INotebookKernelInfoDto, IEditor, INotebookRendererInfo, IOutputRenderRequest, IOutputRenderResponse, INotebookDocumentFilter } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NOTEBOOK_DISPLAY_ORDER, NotebookCellOutputsSplice, NotebookDocumentMetadata, NotebookCellMetadata, ICellEditOperation, ACCESSIBLE_NOTEBOOK_DISPLAY_ORDER, CellEditType, CellKind, INotebookKernelInfo, INotebookKernelInfoDto, IEditor, INotebookDocumentFilter } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
Expand Down Expand Up @@ -171,7 +171,6 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
private readonly _notebookProviders = new Map<string, IMainNotebookController>();
private readonly _notebookKernels = new Map<string, MainThreadNotebookKernel>();
private readonly _notebookKernelProviders = new Map<number, { extension: NotebookExtensionDescription, emitter: Emitter<void>, provider: IDisposable }>();
private readonly _notebookRenderers = new Map<string, MainThreadNotebookRenderer>();
private readonly _proxy: ExtHostNotebookShape;
private _toDisposeOnEditorRemove = new Map<string, IDisposable>();
private _currentState?: DocumentAndEditorState;
Expand All @@ -191,10 +190,10 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
this.registerListeners();
}

async $tryApplyEdits(viewType: string, resource: UriComponents, modelVersionId: number, edits: ICellEditOperation[], renderers: number[]): Promise<boolean> {
async $tryApplyEdits(viewType: string, resource: UriComponents, modelVersionId: number, edits: ICellEditOperation[]): Promise<boolean> {
const textModel = this._notebookService.getNotebookTextModel(URI.from(resource));
if (textModel) {
await this._notebookService.transformEditsOutputs(textModel, edits);
this._notebookService.transformEditsOutputs(textModel, edits);
return textModel.$applyEdit(modelVersionId, edits, true);
}

Expand Down Expand Up @@ -414,22 +413,6 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
// }
}

async $registerNotebookRenderer(extension: NotebookExtensionDescription, type: string, selectors: INotebookMimeTypeSelector, preloads: UriComponents[]): Promise<void> {
const staticContribution = this._notebookService.getContributedNotebookOutputRenderers(type);

if (!staticContribution) {
throw new Error(`Notebook renderer for '${type}' is not statically registered.`);
}

const renderer = new MainThreadNotebookRenderer(this._proxy, type, staticContribution.displayName, extension.id, URI.revive(extension.location), selectors, preloads.map(uri => URI.revive(uri)));
this._notebookRenderers.set(type, renderer);
this._notebookService.registerNotebookRenderer(type, renderer);
}

async $unregisterNotebookRenderer(id: string): Promise<void> {
this._notebookService.unregisterNotebookRenderer(id);
}

async $registerNotebookProvider(_extension: NotebookExtensionDescription, _viewType: string, _supportBackup: boolean, _kernel: INotebookKernelInfoDto | undefined): Promise<void> {
const controller: IMainNotebookController = {
kernel: _kernel,
Expand All @@ -448,7 +431,7 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
{ editType: CellEditType.Insert, index: 0, cells: data.cells }
];

await this._notebookService.transformEditsOutputs(mainthreadTextModel, edits);
this._notebookService.transformEditsOutputs(mainthreadTextModel, edits);
await new Promise(resolve => {
DOM.scheduleAtNextAnimationFrame(() => {
const ret = mainthreadTextModel!.$applyEdit(mainthreadTextModel!.versionId, edits, true);
Expand Down Expand Up @@ -609,12 +592,12 @@ export class MainThreadNotebooks extends Disposable implements MainThreadNoteboo
textModel?.updateNotebookCellMetadata(handle, metadata);
}

async $spliceNotebookCellOutputs(viewType: string, resource: UriComponents, cellHandle: number, splices: NotebookCellOutputsSplice[], renderers: number[]): Promise<void> {
async $spliceNotebookCellOutputs(viewType: string, resource: UriComponents, cellHandle: number, splices: NotebookCellOutputsSplice[]): Promise<void> {
this.logService.debug('MainThreadNotebooks#spliceNotebookCellOutputs', resource.path, cellHandle);
const textModel = this._notebookService.getNotebookTextModel(URI.from(resource));

if (textModel) {
await this._notebookService.transformSpliceOutputs(textModel, splices);
this._notebookService.transformSpliceOutputs(textModel, splices);
textModel.$spliceNotebookCellOutputs(cellHandle, splices);
}
}
Expand Down Expand Up @@ -675,25 +658,3 @@ export class MainThreadNotebookKernel implements INotebookKernelInfo {
return this._proxy.$executeNotebook2(this.id, viewType, uri, handle);
}
}

export class MainThreadNotebookRenderer implements INotebookRendererInfo {
constructor(
private readonly _proxy: ExtHostNotebookShape,
readonly id: string,
public displayName: string,
readonly extensionId: ExtensionIdentifier,
readonly extensionLocation: URI,
readonly selectors: INotebookMimeTypeSelector,
readonly preloads: URI[],
) {

}

render(uri: URI, request: IOutputRenderRequest<UriComponents>): Promise<IOutputRenderResponse<UriComponents> | undefined> {
return this._proxy.$renderOutputs(uri, this.id, request);
}

render2<T>(uri: URI, request: IOutputRenderRequest<T>): Promise<IOutputRenderResponse<T> | undefined> {
return this._proxy.$renderOutputs2(uri, this.id, request);
}
}
4 changes: 0 additions & 4 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -948,10 +948,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
checkProposedApiEnabled(extension);
return extHostNotebook.registerNotebookKernelProvider(extension, selector, provider);
},
registerNotebookOutputRenderer: (type: string, outputFilter: vscode.NotebookOutputSelector, renderer: vscode.NotebookOutputRenderer) => {
checkProposedApiEnabled(extension);
return extHostNotebook.registerNotebookOutputRenderer(type, extension, outputFilter, renderer);
},
get activeNotebookEditor(): vscode.NotebookEditor | undefined {
checkProposedApiEnabled(extension);
return extHostNotebook.activeNotebookEditor;
Expand Down
8 changes: 2 additions & 6 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { TunnelDto } from 'vs/workbench/api/common/extHostTunnelService';
import { TunnelOptions } from 'vs/platform/remote/common/tunnel';
import { Timeline, TimelineChangeEvent, TimelineOptions, TimelineProviderDescriptor, InternalTimelineOptions } from 'vs/workbench/contrib/timeline/common/timeline';
import { revive } from 'vs/base/common/marshalling';
import { INotebookMimeTypeSelector, IProcessedOutput, INotebookDisplayOrder, NotebookCellMetadata, NotebookDocumentMetadata, ICellEditOperation, NotebookCellsChangedEvent, NotebookDataDto, INotebookKernelInfoDto, IMainCellDto, IOutputRenderRequest, IOutputRenderResponse, INotebookDocumentFilter, INotebookKernelInfoDto2 } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IProcessedOutput, INotebookDisplayOrder, NotebookCellMetadata, NotebookDocumentMetadata, ICellEditOperation, NotebookCellsChangedEvent, NotebookDataDto, INotebookKernelInfoDto, IMainCellDto, INotebookDocumentFilter, INotebookKernelInfoDto2 } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CallHierarchyItem } from 'vs/workbench/contrib/callHierarchy/common/callHierarchy';
import { Dto } from 'vs/base/common/types';
import { ISerializableEnvironmentVariableCollection } from 'vs/workbench/contrib/terminal/common/environmentVariable';
Expand Down Expand Up @@ -701,8 +701,6 @@ export interface MainThreadNotebookShape extends IDisposable {
$registerNotebookProvider(extension: NotebookExtensionDescription, viewType: string, supportBackup: boolean, kernelInfoDto: INotebookKernelInfoDto | undefined): Promise<void>;
$onNotebookChange(viewType: string, resource: UriComponents): Promise<void>;
$unregisterNotebookProvider(viewType: string): Promise<void>;
$registerNotebookRenderer(extension: NotebookExtensionDescription, type: string, selectors: INotebookMimeTypeSelector, preloads: UriComponents[]): Promise<void>;
$unregisterNotebookRenderer(id: string): Promise<void>;
$registerNotebookKernel(extension: NotebookExtensionDescription, id: string, label: string, selectors: (string | IRelativePattern)[], preloads: UriComponents[]): Promise<void>;
$registerNotebookKernelProvider(extension: NotebookExtensionDescription, handle: number, documentFilter: INotebookDocumentFilter): Promise<void>;
$unregisterNotebookKernelProvider(handle: number): Promise<void>;
Expand All @@ -712,7 +710,7 @@ export interface MainThreadNotebookShape extends IDisposable {
$updateNotebookLanguages(viewType: string, resource: UriComponents, languages: string[]): Promise<void>;
$updateNotebookMetadata(viewType: string, resource: UriComponents, metadata: NotebookDocumentMetadata): Promise<void>;
$updateNotebookCellMetadata(viewType: string, resource: UriComponents, handle: number, metadata: NotebookCellMetadata | undefined): Promise<void>;
$spliceNotebookCellOutputs(viewType: string, resource: UriComponents, cellHandle: number, splices: NotebookCellOutputsSplice[], renderers: number[]): Promise<void>;
$spliceNotebookCellOutputs(viewType: string, resource: UriComponents, cellHandle: number, splices: NotebookCellOutputsSplice[]): Promise<void>;
$postMessage(editorId: string, forRendererId: string | undefined, value: any): Promise<boolean>;

$onDidEdit(resource: UriComponents, viewType: string, editId: number, label: string | undefined): void;
Expand Down Expand Up @@ -1628,8 +1626,6 @@ export interface ExtHostNotebookShape {
$backup(viewType: string, uri: UriComponents, cancellation: CancellationToken): Promise<string | undefined>;
$acceptDisplayOrder(displayOrder: INotebookDisplayOrder): void;
$acceptNotebookActiveKernelChange(event: { uri: UriComponents, providerHandle: number | undefined, kernelId: string | undefined }): void;
$renderOutputs(uriComponents: UriComponents, id: string, request: IOutputRenderRequest<UriComponents>): Promise<IOutputRenderResponse<UriComponents> | undefined>;
$renderOutputs2<T>(uriComponents: UriComponents, id: string, request: IOutputRenderRequest<T>): Promise<IOutputRenderResponse<T> | undefined>;
$onDidReceiveMessage(editorId: string, rendererId: string | undefined, message: unknown): void;
$acceptModelChanged(uriComponents: UriComponents, event: NotebookCellsChangedEvent): void;
$acceptModelSaved(uriComponents: UriComponents): void;
Expand Down
Loading