Add sample Notebook provider (#17988)

This commit is contained in:
Charles Gagnon
2022-01-05 09:14:54 -08:00
committed by GitHub
parent 4a2b31f3ba
commit b2c919e054
14 changed files with 286 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as vscode from 'vscode';
/**
* Sample hardcoded contents for the Notebook.
*/
const presetNotebookData: vscode.NotebookData = {
cells: [{
kind: vscode.NotebookCellKind.Markup,
value: 'Sample markup cell',
languageId: 'Markup'
}, {
kind: vscode.NotebookCellKind.Code,
value: '1+1',
languageId: 'Python'
}]
};
const presetNotebookBytes = new TextEncoder().encode(JSON.stringify(presetNotebookData));
/**
* A sample Notebook serializer which handles serializing/deserializing the Notebook from/into a byte array for storage.
*/
export class SampleSerializer implements vscode.NotebookSerializer {
deserializeNotebook(content: Uint8Array, token: vscode.CancellationToken): vscode.NotebookData | Thenable<vscode.NotebookData> {
return presetNotebookData;
}
serializeNotebook(data: vscode.NotebookData, token: vscode.CancellationToken): Uint8Array | Thenable<Uint8Array> {
return presetNotebookBytes;
}
}