Skip to content

Commit

Permalink
declare cancellation support for openNotebook and wire it up, exempt …
Browse files Browse the repository at this point in the history
…notebook content provider from provider naming rules
  • Loading branch information
jrieken committed Mar 9, 2021
1 parent 0e04c15 commit 98a22a9
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,8 @@
"CustomEditorProvider",
"CustomReadonlyEditorProvider",
"TerminalLinkProvider",
"AuthenticationProvider"
"AuthenticationProvider",
"NotebookContentProvider"
]
}
],
Expand Down
26 changes: 13 additions & 13 deletions src/vs/vscode.proposed.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<NotebookDocumentContentOptions>;

// todo@API remove! against separation of data provider and renderer
// eslint-disable-next-line vscode-dts-cancellation
resolveNotebook(document: NotebookDocument, webview: NotebookCommunication): Thenable<void>;

/**
* 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<NotebookData>;
// eslint-disable-next-line vscode-dts-provider-naming
// eslint-disable-next-line vscode-dts-cancellation
resolveNotebook(document: NotebookDocument, webview: NotebookCommunication): Thenable<void>;
// eslint-disable-next-line vscode-dts-provider-naming
saveNotebook(document: NotebookDocument, cancellation: CancellationToken): Thenable<void>;
// eslint-disable-next-line vscode-dts-provider-naming
saveNotebookAs(targetResource: Uri, document: NotebookDocument, cancellation: CancellationToken): Thenable<void>;
// eslint-disable-next-line vscode-dts-provider-naming
backupNotebook(document: NotebookDocument, context: NotebookDocumentBackupContext, cancellation: CancellationToken): Thenable<NotebookDocumentBackup>;
openNotebook(uri: Uri, openContext: NotebookDocumentOpenContext, token: CancellationToken): NotebookData | Thenable<NotebookData>;

saveNotebook(document: NotebookDocument, token: CancellationToken): Thenable<void>;

saveNotebookAs(targetResource: Uri, document: NotebookDocument, token: CancellationToken): Thenable<void>;

// ???
// provideKernels(document: NotebookDocument, token: CancellationToken): ProviderResult<T[]>;
backupNotebook(document: NotebookDocument, context: NotebookDocumentBackupContext, token: CancellationToken): Thenable<NotebookDocumentBackup>;
}

export namespace notebook {
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/browser/mainThreadNotebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/api/common/extHost.protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1863,7 +1863,7 @@ export interface ExtHostNotebookShape {
$executeNotebookKernelFromProvider(handle: number, uri: UriComponents, kernelId: string, cellHandle: number | undefined): Promise<void>;
$cancelNotebookKernelFromProvider(handle: number, uri: UriComponents, kernelId: string, cellHandle: number | undefined): Promise<void>;
$onDidReceiveMessage(editorId: string, rendererId: string | undefined, message: unknown): void;
$openNotebook(viewType: string, uri: UriComponents, backupId?: string): Promise<NotebookDataDto>;
$openNotebook(viewType: string, uri: UriComponents, backupId: string | undefined, token: CancellationToken): Promise<NotebookDataDto>;
$saveNotebook(viewType: string, uri: UriComponents, token: CancellationToken): Promise<boolean>;
$saveNotebookAs(viewType: string, uri: UriComponents, target: UriComponents, token: CancellationToken): Promise<boolean>;
$backupNotebook(viewType: string, uri: UriComponents, cancellation: CancellationToken): Promise<string>;
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/common/extHostNotebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,9 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {

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

async $openNotebook(viewType: string, uri: UriComponents, backupId?: string): Promise<NotebookDataDto> {
async $openNotebook(viewType: string, uri: UriComponents, backupId: string | undefined, token: CancellationToken): Promise<NotebookDataDto> {
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export class NotebookEditorModel extends EditorModel implements INotebookEditorM

private async _loadFromProvider(backupId: string | undefined): Promise<void> {

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()) {
Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/contrib/notebook/common/notebookService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ export const INotebookService = createDecorator<INotebookService>('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<void>;
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<boolean>;
saveAs(uri: URI, target: URI, token: CancellationToken): Promise<boolean>;
backup(uri: URI, token: CancellationToken): Promise<string>;
Expand Down Expand Up @@ -66,7 +67,7 @@ export interface INotebookService {
getNotebookProviderResourceRoots(): URI[];
destoryNotebookDocument(viewType: string, notebook: INotebookTextModel): void;

fetchNotebookRawData(viewType: string, uri: URI, backupId?: string): Promise<INotebookRawData>;
fetchNotebookRawData(viewType: string, uri: URI, backupId: string | undefined, token: CancellationToken): Promise<INotebookRawData>;
save(viewType: string, resource: URI, token: CancellationToken): Promise<boolean>;
saveAs(viewType: string, resource: URI, target: URI, token: CancellationToken): Promise<boolean>;
backup(viewType: string, uri: URI, token: CancellationToken): Promise<string | undefined>;
Expand Down

0 comments on commit 98a22a9

Please sign in to comment.