Johannes 2022-04-20 11:30:31 +02:00
parent 931f4df9dc
commit 8783c56eb7
No known key found for this signature in database
GPG key ID: 6DEF802A22264FCA
3 changed files with 9 additions and 6 deletions

View file

@ -1001,7 +1001,9 @@ suite('Notebook & LiveShare', function () {
suiteDisposables.push(vscode.workspace.registerNotebookSerializer(notebookType, new class implements vscode.NotebookSerializer {
deserializeNotebook(content: Uint8Array, _token: vscode.CancellationToken): vscode.NotebookData | Thenable<vscode.NotebookData> {
const value = new TextDecoder().decode(content);
return new vscode.NotebookData([new vscode.NotebookCellData(vscode.NotebookCellKind.Code, value, 'fooLang')]);
const cell1 = new vscode.NotebookCellData(vscode.NotebookCellKind.Code, value, 'fooLang');
cell1.outputs = [new vscode.NotebookCellOutput([vscode.NotebookCellOutputItem.stderr(value)])];
return new vscode.NotebookData([cell1]);
}
serializeNotebook(data: vscode.NotebookData, _token: vscode.CancellationToken): Uint8Array | Thenable<Uint8Array> {
return new TextEncoder().encode(data.cells[0].value);
@ -1030,6 +1032,7 @@ suite('Notebook & LiveShare', function () {
assert.ok(data instanceof vscode.NotebookData);
assert.strictEqual(data.cells.length, 1);
assert.strictEqual(data.cells[0].value, value);
assert.strictEqual(new TextDecoder().decode(data.cells[0].outputs![0].items[0].data), value);
});
test('command: vscode.executeNotebookToData', async function () {

View file

@ -200,14 +200,14 @@ CommandsRegistry.registerCommand('_executeDataToNotebook', async (accessor, ...a
}
const dto = await info.serializer.dataToNotebook(bytes);
return NotebookDto.toNotebookDataDto(dto);
return new SerializableObjectWithBuffers(NotebookDto.toNotebookDataDto(dto));
});
CommandsRegistry.registerCommand('_executeNotebookToData', async (accessor, ...args) => {
const [notebookType, dto] = args;
assertType(typeof notebookType === 'string', 'string');
assertType(typeof dto === 'object', 'NotebookDataDto');
assertType(typeof dto === 'object');
const notebookService = accessor.get(INotebookService);
const info = await notebookService.withNotebookDataProvider(notebookType);
@ -215,7 +215,7 @@ CommandsRegistry.registerCommand('_executeNotebookToData', async (accessor, ...a
return;
}
const data = NotebookDto.fromNotebookDataDto(dto);
const data = NotebookDto.fromNotebookDataDto(dto.value);
const bytes = await info.serializer.notebookToData(data);
return bytes;
});

View file

@ -523,12 +523,12 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
const commandDataToNotebook = new ApiCommand(
'vscode.executeDataToNotebook', '_executeDataToNotebook', 'Invoke notebook serializer',
[notebookTypeArg, new ApiCommandArgument<Uint8Array, VSBuffer>('data', 'Bytes to convert to data', v => v instanceof Uint8Array, v => VSBuffer.wrap(v))],
new ApiCommandResult<NotebookDataDto, vscode.NotebookData>('Notebook Data', dto => typeConverters.NotebookData.to(dto))
new ApiCommandResult<SerializableObjectWithBuffers<NotebookDataDto>, vscode.NotebookData>('Notebook Data', data => typeConverters.NotebookData.to(data.value))
);
const commandNotebookToData = new ApiCommand(
'vscode.executeNotebookToData', '_executeNotebookToData', 'Invoke notebook serializer',
[notebookTypeArg, new ApiCommandArgument<vscode.NotebookData, NotebookDataDto>('NotebookData', 'Notebook data to convert to bytes', v => true, v => typeConverters.NotebookData.from(v))],
[notebookTypeArg, new ApiCommandArgument<vscode.NotebookData, SerializableObjectWithBuffers<NotebookDataDto>>('NotebookData', 'Notebook data to convert to bytes', v => true, v => new SerializableObjectWithBuffers(typeConverters.NotebookData.from(v)))],
new ApiCommandResult<VSBuffer, Uint8Array>('Bytes', dto => dto.buffer)
);