Skip to content

Commit

Permalink
Remove notebook content provider api (#165195)
Browse files Browse the repository at this point in the history
Fixes #160580
Fixes #147248
  • Loading branch information
mjbvz authored Nov 2, 2022
1 parent bb4e4c4 commit 7233e19
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,11 @@ async function assertKernel(kernel: Kernel, notebook: vscode.NotebookDocument):
assert.ok(kernel.associatedNotebooks.has(notebook.uri.toString()));
}

const apiTestContentProvider: vscode.NotebookContentProvider = {
openNotebook: async (resource: vscode.Uri): Promise<vscode.NotebookData> => {
if (/.*empty\-.*\.vsctestnb$/.test(resource.path)) {
return {
metadata: {},
cells: []
};
}

const apiTestSerializer: vscode.NotebookSerializer = {
serializeNotebook(_data, _token) {
return new Uint8Array();
},
deserializeNotebook(_content, _token) {
const dto: vscode.NotebookData = {
metadata: { custom: { testMetadata: false } },
cells: [
Expand Down Expand Up @@ -143,8 +139,8 @@ const apiTestContentProvider: vscode.NotebookContentProvider = {
suiteDisposables.length = 0;
});

suiteSetup(function () {
suiteDisposables.push(vscode.workspace.registerNotebookContentProvider('notebookCoreTest', apiTestContentProvider));
suiteSetup(() => {
suiteDisposables.push(vscode.workspace.registerNotebookSerializer('notebookCoreTest', apiTestSerializer));
});

let defaultKernel: Kernel;
Expand Down
57 changes: 7 additions & 50 deletions src/vs/workbench/api/browser/mainThreadNotebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ import { VSBuffer } from 'vs/base/common/buffer';
import { CancellationToken } from 'vs/base/common/cancellation';
import { Emitter } from 'vs/base/common/event';
import { DisposableStore, dispose, IDisposable } from 'vs/base/common/lifecycle';
import { StopWatch } from 'vs/base/common/stopwatch';
import { assertType } from 'vs/base/common/types';
import { URI } from 'vs/base/common/uri';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { ILogService } from 'vs/platform/log/common/log';
import { NotebookDto } from 'vs/workbench/api/browser/mainThreadNotebookDto';
import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
import { INotebookCellStatusBarItemProvider, INotebookContributionData, NotebookData as NotebookData, NotebookExtensionDescription, TransientOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookContentProvider, INotebookService, SimpleNotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookService';
import { INotebookCellStatusBarItemProvider, INotebookContributionData, NotebookData, NotebookExtensionDescription, TransientOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookService, SimpleNotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookService';
import { extHostNamedCustomer, IExtHostContext } from 'vs/workbench/services/extensions/common/extHostCustomers';
import { SerializableObjectWithBuffers } from 'vs/workbench/services/extensions/common/proxyIdentifier';
import { ExtHostContext, ExtHostNotebookShape, MainContext, MainThreadNotebookShape } from '../common/extHost.protocol';
import { ILogService } from 'vs/platform/log/common/log';
import { StopWatch } from 'vs/base/common/stopwatch';
import { CommandsRegistry } from 'vs/platform/commands/common/commands';
import { assertType } from 'vs/base/common/types';

@extHostNamedCustomer(MainContext.MainThreadNotebook)
export class MainThreadNotebooks implements MainThreadNotebookShape {

private readonly _disposables = new DisposableStore();

private readonly _proxy: ExtHostNotebookShape;
private readonly _notebookProviders = new Map<string, { controller: INotebookContentProvider; disposable: IDisposable }>();
private readonly _notebookSerializer = new Map<number, IDisposable>();
private readonly _notebookCellStatusBarRegistrations = new Map<number, IDisposable>();

Expand All @@ -41,51 +40,9 @@ export class MainThreadNotebooks implements MainThreadNotebookShape {

dispose(): void {
this._disposables.dispose();
// remove all notebook providers
for (const item of this._notebookProviders.values()) {
item.disposable.dispose();
}
dispose(this._notebookSerializer.values());
}

async $registerNotebookProvider(extension: NotebookExtensionDescription, viewType: string, options: TransientOptions, data: INotebookContributionData | undefined): Promise<void> {
const contentOptions = { ...options };

const controller: INotebookContentProvider = {
get options() {
return contentOptions;
},
set options(newOptions) {
contentOptions.transientCellMetadata = newOptions.transientCellMetadata;
contentOptions.transientDocumentMetadata = newOptions.transientDocumentMetadata;
contentOptions.transientOutputs = newOptions.transientOutputs;
},
open: async (uri: URI, backupId: string | undefined, untitledDocumentData: VSBuffer | undefined, token: CancellationToken) => {
const data = await this._proxy.$openNotebook(viewType, uri, backupId, untitledDocumentData, token);
return {
data: NotebookDto.fromNotebookDataDto(data.value),
transientOptions: contentOptions
};
},
backup: async (uri: URI, token: CancellationToken) => ''
};

const disposable = new DisposableStore();
disposable.add(this._notebookService.registerNotebookController(viewType, extension, controller));
if (data) {
disposable.add(this._notebookService.registerContributedNotebookType(viewType, data));
}
this._notebookProviders.set(viewType, { controller, disposable });
}

async $unregisterNotebookProvider(viewType: string): Promise<void> {
const entry = this._notebookProviders.get(viewType);
if (entry) {
entry.disposable.dispose();
this._notebookProviders.delete(viewType);
}
}

$registerNotebookSerializer(handle: number, extension: NotebookExtensionDescription, viewType: string, options: TransientOptions, data: INotebookContributionData | undefined): void {
const registration = this._notebookService.registerNotebookSerializer(viewType, extension, {
options,
Expand Down
8 changes: 0 additions & 8 deletions src/vs/workbench/api/common/extHost.api.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -937,14 +937,6 @@ export function createApiFactoryAndRegisterActors(accessor: ServicesAccessor): I
registerNotebookSerializer(viewType: string, serializer: vscode.NotebookSerializer, options?: vscode.NotebookDocumentContentOptions, registration?: vscode.NotebookRegistrationData) {
return extHostNotebook.registerNotebookSerializer(extension, viewType, serializer, options, isProposedApiEnabled(extension, 'notebookLiveShare') ? registration : undefined);
},
registerNotebookContentProvider: (viewType: string, provider: vscode.NotebookContentProvider, options?: vscode.NotebookDocumentContentOptions, registration?: vscode.NotebookRegistrationData) => {
checkProposedApiEnabled(extension, 'notebookContentProvider');

extHostApiDeprecation.report('workspace.registerNotebookContentProvider', extension,
`The notebookContentProvider API is not on track for finalization and will be removed.`);

return extHostNotebook.registerNotebookContentProvider(extension, viewType, provider, options);
},
onDidChangeConfiguration: (listener: (_: any) => any, thisArgs?: any, disposables?: extHostTypes.Disposable[]) => {
return configProvider.onDidChangeConfiguration(listener, thisArgs, disposables);
},
Expand Down
5 changes: 0 additions & 5 deletions src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -964,9 +964,6 @@ export interface INotebookCellStatusBarListDto {
}

export interface MainThreadNotebookShape extends IDisposable {
$registerNotebookProvider(extension: notebookCommon.NotebookExtensionDescription, viewType: string, options: notebookCommon.TransientOptions, registration: notebookCommon.INotebookContributionData | undefined): Promise<void>;
$unregisterNotebookProvider(viewType: string): Promise<void>;

$registerNotebookSerializer(handle: number, extension: notebookCommon.NotebookExtensionDescription, viewType: string, options: notebookCommon.TransientOptions, registration: notebookCommon.INotebookContributionData | undefined): void;
$unregisterNotebookSerializer(handle: number): void;

Expand Down Expand Up @@ -2063,8 +2060,6 @@ export interface ExtHostNotebookShape extends ExtHostNotebookDocumentsAndEditors
$provideNotebookCellStatusBarItems(handle: number, uri: UriComponents, index: number, token: CancellationToken): Promise<INotebookCellStatusBarListDto | undefined>;
$releaseNotebookCellStatusBarItems(id: number): void;

$openNotebook(viewType: string, uri: UriComponents, backupId: string | undefined, untitledDocumentData: VSBuffer | undefined, token: CancellationToken): Promise<SerializableObjectWithBuffers<NotebookDataDto>>;

$dataToNotebook(handle: number, data: VSBuffer, token: CancellationToken): Promise<SerializableObjectWithBuffers<NotebookDataDto>>;
$notebookToData(handle: number, data: SerializableObjectWithBuffers<NotebookDataDto>, token: CancellationToken): Promise<VSBuffer>;
}
Expand Down
47 changes: 0 additions & 47 deletions src/vs/workbench/api/common/extHostNotebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ import { ExtHostCell, ExtHostNotebookDocument } from './extHostNotebookDocument'
import { ExtHostNotebookEditor } from './extHostNotebookEditor';


type NotebookContentProviderData = {
readonly provider: vscode.NotebookContentProvider;
readonly extension: IExtensionDescription;
};

export class ExtHostNotebookController implements ExtHostNotebookShape {
private static _notebookStatusBarItemProviderHandlePool: number = 0;
Expand All @@ -40,7 +36,6 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
private readonly _notebookDocumentsProxy: MainThreadNotebookDocumentsShape;
private readonly _notebookEditorsProxy: MainThreadNotebookEditorsShape;

private readonly _notebookContentProviders = new Map<string, NotebookContentProviderData>();
private readonly _notebookStatusBarItemProviders = new Map<number, vscode.NotebookCellStatusBarItemProvider>();
private readonly _documents = new ResourceMap<ExtHostNotebookDocument>();
private readonly _editors = new Map<string, ExtHostNotebookEditor>();
Expand Down Expand Up @@ -137,41 +132,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
return result;
}

private _getProviderData(viewType: string): NotebookContentProviderData {
const result = this._notebookContentProviders.get(viewType);
if (!result) {
throw new Error(`NO provider for '${viewType}'`);
}
return result;
}

registerNotebookContentProvider(
extension: IExtensionDescription,
viewType: string,
provider: vscode.NotebookContentProvider,
options?: vscode.NotebookDocumentContentOptions
): vscode.Disposable {
if (isFalsyOrWhitespace(viewType)) {
throw new Error(`viewType cannot be empty or just whitespace`);
}
if (this._notebookContentProviders.has(viewType)) {
throw new Error(`Notebook provider for '${viewType}' already registered`);
}

this._notebookContentProviders.set(viewType, { extension, provider });

this._notebookProxy.$registerNotebookProvider(
{ id: extension.identifier, location: extension.extensionLocation },
viewType,
typeConverters.NotebookDocumentContentOptions.from(options),
undefined,
);

return new extHostTypes.Disposable(() => {
this._notebookContentProviders.delete(viewType);
this._notebookProxy.$unregisterNotebookProvider(viewType);
});
}

private static _convertNotebookRegistrationData(extension: IExtensionDescription, registration: vscode.NotebookRegistrationData | undefined): INotebookContributionData | undefined {
if (!registration) {
Expand Down Expand Up @@ -341,14 +302,6 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {

// --- open, save, saveAs, backup

async $openNotebook(viewType: string, uri: UriComponents, backupId: string | undefined, untitledDocumentData: VSBuffer | undefined, token: CancellationToken): Promise<SerializableObjectWithBuffers<NotebookDataDto>> {
const { provider } = this._getProviderData(viewType);
const data = await provider.openNotebook(URI.revive(uri), { backupId, untitledDocumentData: untitledDocumentData?.buffer }, token);
return new SerializableObjectWithBuffers({
metadata: data.metadata ?? Object.create(null),
cells: data.cells.map(typeConverters.NotebookCellData.from),
});
}

private _createExtHostEditor(document: ExtHostNotebookDocument, editorId: string, data: INotebookEditorAddData) {

Expand Down
8 changes: 3 additions & 5 deletions src/vs/workbench/api/test/browser/extHostNotebook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,15 @@ suite('NotebookCell#Document', function () {
override $registerCommand() { }
});
rpcProtocol.set(MainContext.MainThreadNotebook, new class extends mock<MainThreadNotebookShape>() {
override async $registerNotebookProvider() { }
override async $unregisterNotebookProvider() { }
override async $registerNotebookSerializer() { }
override async $unregisterNotebookSerializer() { }
});
extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService());
extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
extHostNotebooks = new ExtHostNotebookController(rpcProtocol, new ExtHostCommands(rpcProtocol, new NullLogService()), extHostDocumentsAndEditors, extHostDocuments);
extHostNotebookDocuments = new ExtHostNotebookDocuments(extHostNotebooks);

const reg = extHostNotebooks.registerNotebookContentProvider(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookContentProvider>() {
// async openNotebook() { }
});
const reg = extHostNotebooks.registerNotebookSerializer(nullExtensionDescription, 'test', new class extends mock<vscode.NotebookSerializer>() { });
extHostNotebooks.$acceptDocumentAndEditorsDelta(new SerializableObjectWithBuffers({
addedDocuments: [{
uri: notebookUri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ suite('NotebookKernel', function () {

});
rpcProtocol.set(MainContext.MainThreadNotebook, new class extends mock<MainThreadNotebookShape>() {
override async $registerNotebookProvider() { }
override async $unregisterNotebookProvider() { }
override async $registerNotebookSerializer() { }
override async $unregisterNotebookSerializer() { }
});
extHostDocumentsAndEditors = new ExtHostDocumentsAndEditors(rpcProtocol, new NullLogService());
extHostDocuments = new ExtHostDocuments(rpcProtocol, extHostDocumentsAndEditors);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
}

if (!this._webview) {
this._createWebview(this.getId(), this.textModel.viewType, this.textModel.uri);
this._ensureWebview(this.getId(), this.textModel.viewType, this.textModel.uri);
}

this._webviewResolvePromise = (async () => {
Expand Down Expand Up @@ -1283,7 +1283,11 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
return this._webviewResolvePromise;
}

private async _createWebview(id: string, viewType: string, resource: URI): Promise<void> {
private _ensureWebview(id: string, viewType: string, resource: URI) {
if (this._webview) {
return;
}

const that = this;

this._webview = this.instantiationService.createInstance(BackLayerWebView, {
Expand Down Expand Up @@ -1316,7 +1320,8 @@ export class NotebookEditorWidget extends Disposable implements INotebookEditorD
}

private async _attachModel(textModel: NotebookTextModel, viewState: INotebookEditorViewState | undefined, perf?: NotebookPerfMarks) {
await this._createWebview(this.getId(), textModel.viewType, textModel.uri);
this._ensureWebview(this.getId(), textModel.viewType, textModel.uri);

this.viewModel = this.instantiationService.createInstance(NotebookViewModel, textModel.viewType, textModel, this._viewContext, this.getLayoutInfo(), { isReadOnly: this._readOnly });
this._viewContext.eventDispatcher.emit([new NotebookLayoutChangedEvent({ width: true, fontInfo: true }, this.getLayoutInfo())]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const allApiProposals = Object.freeze({
interactiveWindow: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.interactiveWindow.d.ts',
ipc: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.ipc.d.ts',
notebookCellExecutionState: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookCellExecutionState.d.ts',
notebookContentProvider: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookContentProvider.d.ts',
notebookControllerAffinityHidden: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookControllerAffinityHidden.d.ts',
notebookControllerKind: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookControllerKind.d.ts',
notebookDeprecated: 'https://raw.githubusercontent.com/microsoft/vscode/main/src/vscode-dts/vscode.proposed.notebookDeprecated.d.ts',
Expand Down
35 changes: 0 additions & 35 deletions src/vscode-dts/vscode.proposed.notebookContentProvider.d.ts

This file was deleted.

0 comments on commit 7233e19

Please sign in to comment.