diff --git a/.eslintrc.json b/.eslintrc.json index 1085686e464..e21cd93df02 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -985,7 +985,8 @@ "CustomEditorProvider", "CustomReadonlyEditorProvider", "TerminalLinkProvider", - "AuthenticationProvider" + "AuthenticationProvider", + "NotebookContentProvider" ] } ], diff --git a/src/vs/vscode.proposed.d.ts b/src/vs/vscode.proposed.d.ts index fc6dd15a2df..59100d9aaf9 100644 --- a/src/vs/vscode.proposed.d.ts +++ b/src/vs/vscode.proposed.d.ts @@ -1555,27 +1555,27 @@ declare module 'vscode' { readonly backupId?: string; } + // todo@API use openNotebookDOCUMENT to align with openCustomDocument etc? export interface NotebookContentProvider { + readonly options?: NotebookDocumentContentOptions; readonly onDidChangeNotebookContentOptions?: Event; + + // todo@API remove! against separation of data provider and renderer + // eslint-disable-next-line vscode-dts-cancellation + resolveNotebook(document: NotebookDocument, webview: NotebookCommunication): Thenable; + /** * Content providers should always use [file system providers](#FileSystemProvider) to * resolve the raw content for `uri` as the resouce is not necessarily a file on disk. */ - // eslint-disable-next-line vscode-dts-provider-naming - openNotebook(uri: Uri, openContext: NotebookDocumentOpenContext): NotebookData | Thenable; - // eslint-disable-next-line vscode-dts-provider-naming - // eslint-disable-next-line vscode-dts-cancellation - resolveNotebook(document: NotebookDocument, webview: NotebookCommunication): Thenable; - // eslint-disable-next-line vscode-dts-provider-naming - saveNotebook(document: NotebookDocument, cancellation: CancellationToken): Thenable; - // eslint-disable-next-line vscode-dts-provider-naming - saveNotebookAs(targetResource: Uri, document: NotebookDocument, cancellation: CancellationToken): Thenable; - // eslint-disable-next-line vscode-dts-provider-naming - backupNotebook(document: NotebookDocument, context: NotebookDocumentBackupContext, cancellation: CancellationToken): Thenable; + openNotebook(uri: Uri, openContext: NotebookDocumentOpenContext, token: CancellationToken): NotebookData | Thenable; - // ??? - // provideKernels(document: NotebookDocument, token: CancellationToken): ProviderResult; + saveNotebook(document: NotebookDocument, token: CancellationToken): Thenable; + + saveNotebookAs(targetResource: Uri, document: NotebookDocument, token: CancellationToken): Thenable; + + backupNotebook(document: NotebookDocument, context: NotebookDocumentBackupContext, token: CancellationToken): Thenable; } export namespace notebook { diff --git a/src/vs/workbench/api/browser/mainThreadNotebook.ts b/src/vs/workbench/api/browser/mainThreadNotebook.ts index 0788ef388a5..02742173831 100644 --- a/src/vs/workbench/api/browser/mainThreadNotebook.ts +++ b/src/vs/workbench/api/browser/mainThreadNotebook.ts @@ -403,8 +403,8 @@ export class MainThreadNotebooks implements MainThreadNotebookShape { contentOptions.transientOutputs = newOptions.transientOutputs; }, viewOptions: options.viewOptions, - openNotebook: async (viewType: string, uri: URI, backupId?: string) => { - const data = await this._proxy.$openNotebook(viewType, uri, backupId); + openNotebook: async (viewType: string, uri: URI, backupId: string | undefined, token: CancellationToken) => { + const data = await this._proxy.$openNotebook(viewType, uri, backupId, token); return { data, transientOptions: contentOptions diff --git a/src/vs/workbench/api/common/extHost.protocol.ts b/src/vs/workbench/api/common/extHost.protocol.ts index 297d95919fb..7269a63dcfd 100644 --- a/src/vs/workbench/api/common/extHost.protocol.ts +++ b/src/vs/workbench/api/common/extHost.protocol.ts @@ -1863,7 +1863,7 @@ export interface ExtHostNotebookShape { $executeNotebookKernelFromProvider(handle: number, uri: UriComponents, kernelId: string, cellHandle: number | undefined): Promise; $cancelNotebookKernelFromProvider(handle: number, uri: UriComponents, kernelId: string, cellHandle: number | undefined): Promise; $onDidReceiveMessage(editorId: string, rendererId: string | undefined, message: unknown): void; - $openNotebook(viewType: string, uri: UriComponents, backupId?: string): Promise; + $openNotebook(viewType: string, uri: UriComponents, backupId: string | undefined, token: CancellationToken): Promise; $saveNotebook(viewType: string, uri: UriComponents, token: CancellationToken): Promise; $saveNotebookAs(viewType: string, uri: UriComponents, target: UriComponents, token: CancellationToken): Promise; $backupNotebook(viewType: string, uri: UriComponents, cancellation: CancellationToken): Promise; diff --git a/src/vs/workbench/api/common/extHostNotebook.ts b/src/vs/workbench/api/common/extHostNotebook.ts index 254a0ba8cca..144390d8790 100644 --- a/src/vs/workbench/api/common/extHostNotebook.ts +++ b/src/vs/workbench/api/common/extHostNotebook.ts @@ -497,9 +497,9 @@ export class ExtHostNotebookController implements ExtHostNotebookShape { // --- open, save, saveAs, backup - async $openNotebook(viewType: string, uri: UriComponents, backupId?: string): Promise { + async $openNotebook(viewType: string, uri: UriComponents, backupId: string | undefined, token: CancellationToken): Promise { const { provider } = this._getProviderData(viewType); - const data = await provider.openNotebook(URI.revive(uri), { backupId }); + const data = await provider.openNotebook(URI.revive(uri), { backupId }, token); return { metadata: { ...notebookDocumentMetadataDefaults, diff --git a/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts b/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts index 619c18136d8..60c702c929f 100644 --- a/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts +++ b/src/vs/workbench/contrib/notebook/browser/notebookServiceImpl.ts @@ -512,12 +512,12 @@ export class NotebookService extends Disposable implements INotebookService, IEd return result; } - async fetchNotebookRawData(viewType: string, uri: URI, backupId?: string): Promise<{ data: NotebookDataDto, transientOptions: TransientOptions }> { + async fetchNotebookRawData(viewType: string, uri: URI, backupId: string | undefined, token: CancellationToken): Promise<{ data: NotebookDataDto, transientOptions: TransientOptions }> { if (!await this.canResolve(viewType)) { throw new Error(`CANNOT fetch notebook data, there is NO provider for '${viewType}'`); } const provider = this._withProvider(viewType)!; - return await provider.controller.openNotebook(viewType, uri, backupId); + return await provider.controller.openNotebook(viewType, uri, backupId, token); } async save(viewType: string, resource: URI, token: CancellationToken): Promise { diff --git a/src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts b/src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts index 13748942e86..75406e7a644 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookEditorModel.ts @@ -170,7 +170,7 @@ export class NotebookEditorModel extends EditorModel implements INotebookEditorM private async _loadFromProvider(backupId: string | undefined): Promise { - const data = await this._notebookService.fetchNotebookRawData(this.viewType, this.resource, backupId); + const data = await this._notebookService.fetchNotebookRawData(this.viewType, this.resource, backupId, CancellationToken.None); this._lastResolvedFileStat = await this._resolveStats(this.resource); if (this.isDisposed()) { diff --git a/src/vs/workbench/contrib/notebook/common/notebookService.ts b/src/vs/workbench/contrib/notebook/common/notebookService.ts index db6cea79b0e..e4a628741bf 100644 --- a/src/vs/workbench/contrib/notebook/common/notebookService.ts +++ b/src/vs/workbench/contrib/notebook/common/notebookService.ts @@ -22,9 +22,10 @@ export const INotebookService = createDecorator('notebookServi export interface IMainNotebookController { viewOptions?: { displayName: string; filenamePattern: (string | IRelativePattern | INotebookExclusiveDocumentFilter)[]; exclusive: boolean; }; options: { transientOutputs: boolean; transientMetadata: TransientMetadata; }; - openNotebook(viewType: string, uri: URI, backupId?: string): Promise<{ data: NotebookDataDto, transientOptions: TransientOptions; }>; resolveNotebookEditor(viewType: string, uri: URI, editorId: string): Promise; onDidReceiveMessage(editorId: string, rendererType: string | undefined, message: any): void; + + openNotebook(viewType: string, uri: URI, backupId: string | undefined, token: CancellationToken): Promise<{ data: NotebookDataDto, transientOptions: TransientOptions; }>; save(uri: URI, token: CancellationToken): Promise; saveAs(uri: URI, target: URI, token: CancellationToken): Promise; backup(uri: URI, token: CancellationToken): Promise; @@ -66,7 +67,7 @@ export interface INotebookService { getNotebookProviderResourceRoots(): URI[]; destoryNotebookDocument(viewType: string, notebook: INotebookTextModel): void; - fetchNotebookRawData(viewType: string, uri: URI, backupId?: string): Promise; + fetchNotebookRawData(viewType: string, uri: URI, backupId: string | undefined, token: CancellationToken): Promise; save(viewType: string, resource: URI, token: CancellationToken): Promise; saveAs(viewType: string, resource: URI, target: URI, token: CancellationToken): Promise; backup(viewType: string, uri: URI, token: CancellationToken): Promise;