This commit is contained in:
Johannes Rieken
2021-05-19 15:27:23 +02:00
parent 734b79dada
commit 53352a2954
11 changed files with 164 additions and 51 deletions

View File

@@ -254,12 +254,20 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
return new NotebookEditorDecorationType(this._notebookEditorsProxy, options).value;
}
async createNotebookDocument(options: { viewType?: string, content?: vscode.NotebookData } = {}): Promise<URI> {
const canonicalUri = await this._notebookDocumentsProxy.$tryCreateNotebook({
viewType: options.viewType,
content: options.content && typeConverters.NotebookData.from(options.content)
});
return URI.revive(canonicalUri);
}
async openNotebookDocument(uri: URI): Promise<vscode.NotebookDocument> {
const cached = this._documents.get(uri);
if (cached) {
return cached.apiNotebook;
}
const canonicalUri = await this._notebookDocumentsProxy.$tryOpenDocument(uri);
const canonicalUri = await this._notebookDocumentsProxy.$tryOpenNotebook(uri);
const document = this._documents.get(URI.revive(canonicalUri));
return assertIsDefined(document?.apiNotebook);
}
@@ -358,19 +366,8 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
if (!serializer) {
throw new Error('NO serializer found');
}
const data = await serializer.deserializeNotebook(bytes.buffer, token);
const res: NotebookDataDto = {
metadata: typeConverters.NotebookDocumentMetadata.from(data.metadata),
cells: [],
};
for (let cell of data.cells) {
extHostTypes.NotebookCellData.validate(cell);
res.cells.push(typeConverters.NotebookCellData.from(cell));
}
return res;
return typeConverters.NotebookData.from(data);
}
async $notebookToData(handle: number, data: NotebookDataDto, token: CancellationToken): Promise<VSBuffer> {
@@ -378,10 +375,7 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
if (!serializer) {
throw new Error('NO serializer found');
}
const bytes = await serializer.serializeNotebook({
metadata: typeConverters.NotebookDocumentMetadata.to(data.metadata),
cells: data.cells.map(typeConverters.NotebookCellData.to)
}, token);
const bytes = await serializer.serializeNotebook(typeConverters.NotebookData.to(data), token);
return VSBuffer.wrap(bytes);
}