mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-23 17:23:02 -05:00
Add sample Notebook provider (#17988)
This commit is contained in:
35
samples/sample-notebook-provider/src/sampleSerializer.ts
Normal file
35
samples/sample-notebook-provider/src/sampleSerializer.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user