change IOutputItemDto to use real bytes, add many dedicated dto-types for transporting output (which cannot be bytes), remove metadata2 from renderer

This commit is contained in:
Johannes Rieken
2021-06-10 11:18:46 +02:00
parent 1d7b2d4b48
commit d0cc52143b
28 changed files with 470 additions and 315 deletions

View File

@@ -27,6 +27,7 @@ import { IWorkingCopyService } from 'vs/workbench/services/workingCopy/common/wo
import { revive } from 'vs/base/common/marshalling';
import { ResourceNotebookCellEdit } from 'vs/workbench/contrib/bulkEdit/browser/bulkCellEdits';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { NotebookDto } from 'vs/workbench/api/browser/mainThreadNotebookDto';
export function reviveWorkspaceEditDto2(data: IWorkspaceEditDto | undefined): ResourceEdit[] {
if (!data?.edits) {
@@ -40,7 +41,7 @@ export function reviveWorkspaceEditDto2(data: IWorkspaceEditDto | undefined): Re
} else if (edit._type === WorkspaceEditType.Text) {
result.push(new ResourceTextEdit(edit.resource, edit.edit, edit.modelVersionId, edit.metadata));
} else if (edit._type === WorkspaceEditType.Cell) {
result.push(new ResourceNotebookCellEdit(edit.resource, edit.edit, edit.notebookVersionId, edit.metadata));
result.push(new ResourceNotebookCellEdit(edit.resource, NotebookDto.fromCellEditOperationDto(edit.edit), edit.notebookVersionId, edit.metadata));
}
}
return result;

View File

@@ -8,9 +8,10 @@ import { CancellationToken } from 'vs/base/common/cancellation';
import { Emitter } from 'vs/base/common/event';
import { DisposableStore, dispose, IDisposable } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { NotebookDto } from 'vs/workbench/api/browser/mainThreadNotebookDto';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { INotebookCellStatusBarService } from 'vs/workbench/contrib/notebook/common/notebookCellStatusBarService';
import { INotebookCellStatusBarItemProvider, INotebookContributionData, NotebookDataDto, TransientCellMetadata, TransientDocumentMetadata, TransientOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookCellStatusBarItemProvider, INotebookContributionData, NotebookData as NotebookData, TransientCellMetadata, TransientDocumentMetadata, TransientOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookContentProvider, INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { ExtHostContext, ExtHostNotebookShape, IExtHostContext, MainContext, MainThreadNotebookShape, NotebookExtensionDescription } from '../common/extHost.protocol';
@@ -56,7 +57,7 @@ export class MainThreadNotebooks implements MainThreadNotebookShape {
open: async (uri: URI, backupId: string | undefined, untitledDocumentData: VSBuffer | undefined, token: CancellationToken) => {
const data = await this._proxy.$openNotebook(viewType, uri, backupId, untitledDocumentData, token);
return {
data,
data: NotebookDto.fromNotebookDataDto(data),
transientOptions: contentOptions
};
},
@@ -100,14 +101,16 @@ export class MainThreadNotebooks implements MainThreadNotebookShape {
}
}
$registerNotebookSerializer(handle: number, extension: NotebookExtensionDescription, viewType: string, options: TransientOptions, data: INotebookContributionData | undefined): void {
const registration = this._notebookService.registerNotebookSerializer(viewType, extension, {
options,
dataToNotebook: (data: VSBuffer): Promise<NotebookDataDto> => {
return this._proxy.$dataToNotebook(handle, data, CancellationToken.None);
dataToNotebook: async (data: VSBuffer): Promise<NotebookData> => {
const dto = await this._proxy.$dataToNotebook(handle, data, CancellationToken.None);
return NotebookDto.fromNotebookDataDto(dto);
},
notebookToData: (data: NotebookDataDto): Promise<VSBuffer> => {
return this._proxy.$notebookToData(handle, data, CancellationToken.None);
notebookToData: (data: NotebookData): Promise<VSBuffer> => {
return this._proxy.$notebookToData(handle, NotebookDto.toNotebookDataDto(data), CancellationToken.None);
}
});
const disposables = new DisposableStore();

View File

@@ -9,14 +9,15 @@ import { URI, UriComponents } from 'vs/base/common/uri';
import { BoundModelReferenceCollection } from 'vs/workbench/api/browser/mainThreadDocuments';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { IMainCellDto, NotebookCellsChangeType, NotebookDataDto } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookEditorModelResolverService } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverService';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { IUriIdentityService } from 'vs/workbench/services/uriIdentity/common/uriIdentity';
import { ExtHostContext, ExtHostNotebookDocumentsShape, IExtHostContext, MainThreadNotebookDocumentsShape } from '../common/extHost.protocol';
import { ExtHostContext, ExtHostNotebookDocumentsShape, IExtHostContext, MainThreadNotebookDocumentsShape, NotebookCellDto, NotebookCellsChangedEventDto, NotebookDataDto } from '../common/extHost.protocol';
import { MainThreadNotebooksAndEditors } from 'vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors';
import { Schemas } from 'vs/base/common/network';
import { NotebookProviderInfo } from 'vs/workbench/contrib/notebook/common/notebookProvider';
import { NotebookDto } from 'vs/workbench/api/browser/mainThreadNotebookDto';
export class MainThreadNotebookDocuments implements MainThreadNotebookDocumentsShape {
@@ -55,36 +56,59 @@ export class MainThreadNotebookDocuments implements MainThreadNotebookDocumentsS
for (const textModel of notebooks) {
const disposableStore = new DisposableStore();
disposableStore.add(textModel.onDidChangeContent(event => {
const dto = event.rawEvents.map(e => {
const data =
e.kind === NotebookCellsChangeType.ModelChange || e.kind === NotebookCellsChangeType.Initialize
? {
kind: e.kind,
versionId: event.versionId,
changes: e.changes.map(diff => [diff[0], diff[1], diff[2].map(cell => MainThreadNotebookDocuments._cellToDto(cell as NotebookCellTextModel))] as [number, number, IMainCellDto[]])
}
: (
e.kind === NotebookCellsChangeType.Move
? {
kind: e.kind,
index: e.index,
length: e.length,
newIdx: e.newIdx,
versionId: event.versionId,
cells: e.cells.map(cell => MainThreadNotebookDocuments._cellToDto(cell as NotebookCellTextModel))
}
: e
);
return data;
});
const eventDto: NotebookCellsChangedEventDto = {
versionId: event.versionId,
rawEvents: []
};
for (const e of event.rawEvents) {
switch (e.kind) {
case NotebookCellsChangeType.ModelChange:
eventDto.rawEvents.push({
kind: e.kind,
changes: e.changes.map(diff => [diff[0], diff[1], diff[2].map(cell => NotebookDto.toNotebookCellDto(cell as NotebookCellTextModel))] as [number, number, NotebookCellDto[]])
});
break;
case NotebookCellsChangeType.Move:
eventDto.rawEvents.push({
kind: e.kind,
index: e.index,
length: e.length,
newIdx: e.newIdx,
});
break;
case NotebookCellsChangeType.Output:
eventDto.rawEvents.push({
kind: e.kind,
index: e.index,
outputs: e.outputs.map(NotebookDto.toNotebookOutputDto)
});
break;
case NotebookCellsChangeType.OutputItem:
eventDto.rawEvents.push({
kind: e.kind,
index: e.index,
outputId: e.outputId,
outputItems: e.outputItems.map(NotebookDto.toNotebookOutputItemDto),
append: e.append
});
break;
case NotebookCellsChangeType.ChangeLanguage:
case NotebookCellsChangeType.ChangeCellMetadata:
case NotebookCellsChangeType.ChangeCellInternalMetadata:
eventDto.rawEvents.push(e);
break;
}
}
// using the model resolver service to know if the model is dirty or not.
// assuming this is the first listener it can mean that at first the model
// is marked as dirty and that another event is fired
this._proxy.$acceptModelChanged(
textModel.uri,
{ rawEvents: dto, versionId: event.versionId },
eventDto,
this._notebookEditorModelResolverService.isDirty(textModel.uri)
);
@@ -105,19 +129,6 @@ export class MainThreadNotebookDocuments implements MainThreadNotebookDocumentsS
}
}
private static _cellToDto(cell: NotebookCellTextModel): IMainCellDto {
return {
handle: cell.handle,
uri: cell.uri,
source: cell.textBuffer.getLinesContent(),
eol: cell.textBuffer.getEOL(),
language: cell.language,
cellKind: cell.cellKind,
outputs: cell.outputs,
metadata: cell.metadata,
internalMetadata: cell.internalMetadata,
};
}
async $tryCreateNotebook(options: { viewType: string, content?: NotebookDataDto }): Promise<UriComponents> {
@@ -150,11 +161,8 @@ export class MainThreadNotebookDocuments implements MainThreadNotebookDocumentsS
// apply content changes... slightly HACKY -> this triggers a change event
if (options.content) {
ref.object.notebook.reset(
options.content.cells,
options.content.metadata,
ref.object.notebook.transientOptions
);
const data = NotebookDto.fromNotebookDataDto(options.content);
ref.object.notebook.reset(data.cells, data.metadata, ref.object.notebook.transientOptions);
}
return uri;
}

View File

@@ -9,6 +9,7 @@ import { combinedDisposable, DisposableStore, IDisposable } from 'vs/base/common
import { URI } from 'vs/base/common/uri';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { MainThreadNotebookDocuments } from 'vs/workbench/api/browser/mainThreadNotebookDocuments';
import { NotebookDto } from 'vs/workbench/api/browser/mainThreadNotebookDto';
import { MainThreadNotebookEditors } from 'vs/workbench/api/browser/mainThreadNotebookEditors';
import { extHostCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { editorGroupToViewColumn } from 'vs/workbench/common/editor';
@@ -226,17 +227,7 @@ export class MainThreadNotebooksAndEditors {
uri: e.uri,
metadata: e.metadata,
versionId: e.versionId,
cells: e.cells.map(cell => ({
handle: cell.handle,
uri: cell.uri,
source: cell.textBuffer.getLinesContent(),
eol: cell.textBuffer.getEOL(),
language: cell.language,
cellKind: cell.cellKind,
outputs: cell.outputs,
metadata: cell.metadata,
internalMetadata: cell.internalMetadata,
}))
cells: e.cells.map(NotebookDto.toNotebookCellDto)
};
}

View File

@@ -0,0 +1,122 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
import * as notebookCommon from 'vs/workbench/contrib/notebook/common/notebookCommon';
export namespace NotebookDto {
export function toNotebookOutputItemDto(item: notebookCommon.IOutputItemDto): extHostProtocol.NotebookOutputItemDto {
return {
mime: item.mime,
valueBytes: Array.from(item.data)
};
}
export function toNotebookOutputDto(output: notebookCommon.IOutputDto): extHostProtocol.NotebookOutputDto {
return {
outputId: output.outputId,
metadata: output.metadata,
items: output.outputs.map(toNotebookOutputItemDto)
};
}
export function toNotebookCellDataDto(cell: notebookCommon.ICellDto2): extHostProtocol.NotebookCellDataDto {
return {
cellKind: cell.cellKind,
language: cell.language,
source: cell.source,
outputs: cell.outputs.map(toNotebookOutputDto)
};
}
export function toNotebookDataDto(data: notebookCommon.NotebookData): extHostProtocol.NotebookDataDto {
return {
metadata: data.metadata,
cells: data.cells.map(toNotebookCellDataDto)
};
}
export function fromNotebookOutputItemDto(item: extHostProtocol.NotebookOutputItemDto): notebookCommon.IOutputItemDto {
return {
mime: item.mime,
data: new Uint8Array(item.valueBytes)
};
}
export function fromNotebookOutputDto(output: extHostProtocol.NotebookOutputDto): notebookCommon.IOutputDto {
return {
outputId: output.outputId,
metadata: output.metadata,
outputs: output.items.map(fromNotebookOutputItemDto)
};
}
export function fromNotebookCellDataDto(cell: extHostProtocol.NotebookCellDataDto): notebookCommon.ICellDto2 {
return {
cellKind: cell.cellKind,
language: cell.language,
source: cell.source,
outputs: cell.outputs.map(fromNotebookOutputDto),
metadata: cell.metadata,
internalMetadata: cell.internalMetadata
};
}
export function fromNotebookDataDto(data: extHostProtocol.NotebookDataDto): notebookCommon.NotebookData {
return {
metadata: data.metadata,
cells: data.cells.map(fromNotebookCellDataDto)
};
}
export function toNotebookCellDto(cell: NotebookCellTextModel): extHostProtocol.NotebookCellDto {
return {
handle: cell.handle,
uri: cell.uri,
source: cell.textBuffer.getLinesContent(),
eol: cell.textBuffer.getEOL(),
language: cell.language,
cellKind: cell.cellKind,
outputs: cell.outputs.map(toNotebookOutputDto),
metadata: cell.metadata,
internalMetadata: cell.internalMetadata,
};
}
export function fromCellExecuteEditDto(data: extHostProtocol.CellExecuteEditDto): notebookCommon.IImmediateCellEditOperation {
if (data.editType === notebookCommon.CellEditType.PartialInternalMetadata) {
return data;
} else if (data.editType === notebookCommon.CellEditType.Output) {
return {
editType: data.editType,
handle: data.handle,
append: data.append,
outputs: data.outputs.map(fromNotebookOutputDto)
};
} else {
return {
editType: data.editType,
append: data.append,
outputId: data.outputId,
items: data.items.map(fromNotebookOutputItemDto)
};
}
}
export function fromCellEditOperationDto(edit: extHostProtocol.ICellEditOperationDto): notebookCommon.ICellEditOperation {
if (edit.editType === notebookCommon.CellEditType.Replace) {
return {
editType: edit.editType,
index: edit.index,
count: edit.count,
cells: edit.cells.map(fromNotebookCellDataDto)
};
} else {
return edit;
}
}
}

View File

@@ -6,9 +6,9 @@
import { DisposableStore, dispose } from 'vs/base/common/lifecycle';
import { getNotebookEditorFromEditorPane, INotebookEditor, INotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
import { ExtHostContext, ExtHostNotebookEditorsShape, IExtHostContext, INotebookDocumentShowOptions, INotebookEditorViewColumnInfo, MainThreadNotebookEditorsShape, NotebookEditorRevealType } from '../common/extHost.protocol';
import { ExtHostContext, ExtHostNotebookEditorsShape, ICellEditOperationDto, IExtHostContext, INotebookDocumentShowOptions, INotebookEditorViewColumnInfo, MainThreadNotebookEditorsShape, NotebookEditorRevealType } from '../common/extHost.protocol';
import { MainThreadNotebooksAndEditors } from 'vs/workbench/api/browser/mainThreadNotebookDocumentsAndEditors';
import { ICellEditOperation, INotebookDecorationRenderOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookDecorationRenderOptions } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { ICellRange } from 'vs/workbench/contrib/notebook/common/notebookRange';
import { ILogService } from 'vs/platform/log/common/log';
import { URI, UriComponents } from 'vs/base/common/uri';
@@ -19,6 +19,7 @@ import { IInstantiationService } from 'vs/platform/instantiation/common/instanti
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { editorGroupToViewColumn } from 'vs/workbench/common/editor';
import { equals } from 'vs/base/common/objects';
import { NotebookDto } from 'vs/workbench/api/browser/mainThreadNotebookDto';
class MainThreadNotebook {
@@ -104,7 +105,7 @@ export class MainThreadNotebookEditors implements MainThreadNotebookEditorsShape
}
}
async $tryApplyEdits(editorId: string, modelVersionId: number, cellEdits: ICellEditOperation[]): Promise<boolean> {
async $tryApplyEdits(editorId: string, modelVersionId: number, cellEdits: ICellEditOperationDto[]): Promise<boolean> {
const wrapper = this._mainThreadEditors.get(editorId);
if (!wrapper) {
return false;
@@ -118,7 +119,7 @@ export class MainThreadNotebookEditors implements MainThreadNotebookEditorsShape
return false;
}
//todo@jrieken use proper selection logic!
return editor.textModel.applyEdits(cellEdits, true, undefined, () => undefined, undefined);
return editor.textModel.applyEdits(cellEdits.map(NotebookDto.fromCellEditOperationDto), true, undefined, () => undefined, undefined);
}
async $tryShowNotebookDocument(resource: UriComponents, viewType: string, options: INotebookDocumentShowOptions): Promise<string> {

View File

@@ -10,13 +10,14 @@ import { combinedDisposable, DisposableStore, IDisposable } from 'vs/base/common
import { URI, UriComponents } from 'vs/base/common/uri';
import { IModeService } from 'vs/editor/common/services/modeService';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { NotebookDto } from 'vs/workbench/api/browser/mainThreadNotebookDto';
import { extHostNamedCustomer } from 'vs/workbench/api/common/extHostCustomers';
import { INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookEditorService } from 'vs/workbench/contrib/notebook/browser/notebookEditorService';
import { IImmediateCellEditOperation, INotebookKernel, INotebookKernelChangeEvent } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookKernel, INotebookKernelChangeEvent } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookKernelService } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
import { ExtHostContext, ExtHostNotebookKernelsShape, IExtHostContext, INotebookKernelDto2, MainContext, MainThreadNotebookKernelsShape } from '../common/extHost.protocol';
import { CellExecuteEditDto, ExtHostContext, ExtHostNotebookKernelsShape, IExtHostContext, INotebookKernelDto2, MainContext, MainThreadNotebookKernelsShape } from '../common/extHost.protocol';
abstract class MainThreadKernel implements INotebookKernel {
@@ -225,14 +226,16 @@ export class MainThreadNotebookKernels implements MainThreadNotebookKernelsShape
// --- execution editss
async $applyExecutionEdits(resource: UriComponents, cellEdits: IImmediateCellEditOperation[]): Promise<void> {
async $applyExecutionEdits(resource: UriComponents, cellEdits: CellExecuteEditDto[]): Promise<void> {
const textModel = this._notebookService.getNotebookTextModel(URI.from(resource));
if (!textModel) {
throw new Error(`Can't apply edits to unknown notebook model: ${URI.revive(resource).toString()}`);
}
const edits = cellEdits.map(NotebookDto.fromCellExecuteEditDto);
try {
textModel.applyEdits(cellEdits, true, undefined, () => undefined, undefined, false);
textModel.applyEdits(edits, true, undefined, () => undefined, undefined, false);
} catch (e) {
// Clearing outputs at the same time as the EH calling append/replaceOutputItems is an expected race, and it should be a no-op.
// And any other failure should not throw back to the extension.

View File

@@ -833,16 +833,6 @@ export enum CellOutputKind {
Rich = 3
}
export interface ICellDto {
handle: number;
uri: UriComponents,
source: string[];
language: string;
cellKind: notebookCommon.CellKind;
outputs: notebookCommon.IOutputDto[];
metadata?: notebookCommon.NotebookCellMetadata;
}
export enum NotebookEditorRevealType {
Default = 0,
InCenter = 1,
@@ -884,11 +874,11 @@ export interface MainThreadNotebookEditorsShape extends IDisposable {
$removeNotebookEditorDecorationType(key: string): void;
$trySetSelections(id: string, range: ICellRange[]): void;
$trySetDecorations(id: string, range: ICellRange, decorationKey: string): void;
$tryApplyEdits(editorId: string, modelVersionId: number, cellEdits: notebookCommon.ICellEditOperation[]): Promise<boolean>
$tryApplyEdits(editorId: string, modelVersionId: number, cellEdits: ICellEditOperationDto[]): Promise<boolean>
}
export interface MainThreadNotebookDocumentsShape extends IDisposable {
$tryCreateNotebook(options: { viewType: string, content?: notebookCommon.NotebookDataDto }): Promise<UriComponents>;
$tryCreateNotebook(options: { viewType: string, content?: NotebookDataDto }): Promise<UriComponents>;
$tryOpenNotebook(uriComponents: UriComponents): Promise<UriComponents>;
$trySaveNotebook(uri: UriComponents): Promise<boolean>;
}
@@ -907,6 +897,22 @@ export interface INotebookKernelDto2 {
preloads?: { uri: UriComponents; provides: string[] }[];
}
export interface CellExecuteOutputEditDto {
editType: notebookCommon.CellEditType.Output;
append?: boolean;
handle: number;
outputs: NotebookOutputDto[]
}
export interface CellExecuteOutputItemEditDto {
editType: notebookCommon.CellEditType.OutputItems;
append?: boolean;
outputId: string;
items: NotebookOutputItemDto[]
}
export type CellExecuteEditDto = CellExecuteOutputEditDto | CellExecuteOutputItemEditDto | notebookCommon.ICellPartialInternalMetadataEditByHandle;
export interface MainThreadNotebookKernelsShape extends IDisposable {
$postMessage(handle: number, editorId: string | undefined, message: any): Promise<boolean>;
$addKernel(handle: number, data: INotebookKernelDto2): Promise<void>;
@@ -914,7 +920,7 @@ export interface MainThreadNotebookKernelsShape extends IDisposable {
$removeKernel(handle: number): void;
$updateNotebookPriority(handle: number, uri: UriComponents, value: number | undefined): void;
$applyExecutionEdits(resource: UriComponents, edits: notebookCommon.IImmediateCellEditOperation[]): Promise<void>;
$applyExecutionEdits(resource: UriComponents, edits: CellExecuteEditDto[]): Promise<void>;
}
export interface MainThreadNotebookRenderersShape extends IDisposable {
@@ -1503,12 +1509,22 @@ export interface IWorkspaceTextEditDto {
metadata?: IWorkspaceEditEntryMetadataDto;
}
export type ICellEditOperationDto =
notebookCommon.ICellPartialMetadataEdit
| notebookCommon.IDocumentMetadataEdit
| {
editType: notebookCommon.CellEditType.Replace,
index: number,
count: number,
cells: NotebookCellDataDto[]
};
export interface IWorkspaceCellEditDto {
_type: WorkspaceEditType.Cell;
resource: UriComponents;
edit: notebookCommon.ICellEditOperation;
notebookVersionId?: number;
metadata?: IWorkspaceEditEntryMetadataDto;
edit: ICellEditOperationDto;
}
export interface IWorkspaceEditDto {
@@ -1877,7 +1893,7 @@ export interface INotebookDocumentPropertiesChangeData {
export interface INotebookModelAddedData {
uri: UriComponents;
versionId: number;
cells: notebookCommon.IMainCellDto[],
cells: NotebookCellDto[],
viewType: string;
metadata?: notebookCommon.NotebookDocumentMetadata;
}
@@ -1899,17 +1915,54 @@ export interface INotebookDocumentsAndEditorsDelta {
visibleEditors?: string[];
}
export interface NotebookOutputItemDto {
readonly mime: string;
readonly valueBytes: number[]; // todo@jrieken ugly, should be VSBuffer
}
export interface NotebookOutputDto {
items: NotebookOutputItemDto[];
outputId: string;
metadata?: Record<string, any>;
}
export interface NotebookCellDataDto {
source: string;
language: string;
cellKind: notebookCommon.CellKind;
outputs: NotebookOutputDto[];
metadata?: notebookCommon.NotebookCellMetadata;
internalMetadata?: notebookCommon.NotebookCellInternalMetadata;
}
export interface NotebookDataDto {
readonly cells: NotebookCellDataDto[];
readonly metadata: notebookCommon.NotebookDocumentMetadata;
}
export interface NotebookCellDto {
handle: number;
uri: UriComponents;
eol: string;
source: string[];
language: string;
cellKind: notebookCommon.CellKind;
outputs: NotebookOutputDto[];
metadata?: notebookCommon.NotebookCellMetadata;
internalMetadata?: notebookCommon.NotebookCellInternalMetadata;
}
export interface ExtHostNotebookShape extends ExtHostNotebookDocumentsAndEditorsShape {
$provideNotebookCellStatusBarItems(handle: number, uri: UriComponents, index: number, token: CancellationToken): Promise<INotebookCellStatusBarListDto | undefined>;
$releaseNotebookCellStatusBarItems(id: number): void;
$openNotebook(viewType: string, uri: UriComponents, backupId: string | undefined, untitledDocumentData: VSBuffer | undefined, token: CancellationToken): Promise<notebookCommon.NotebookDataDto>;
$openNotebook(viewType: string, uri: UriComponents, backupId: string | undefined, untitledDocumentData: VSBuffer | 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>;
$dataToNotebook(handle: number, data: VSBuffer, token: CancellationToken): Promise<notebookCommon.NotebookDataDto>;
$notebookToData(handle: number, data: notebookCommon.NotebookDataDto, token: CancellationToken): Promise<VSBuffer>;
$dataToNotebook(handle: number, data: VSBuffer, token: CancellationToken): Promise<NotebookDataDto>;
$notebookToData(handle: number, data: NotebookDataDto, token: CancellationToken): Promise<VSBuffer>;
}
export interface ExtHostNotebookRenderersShape {
@@ -1920,8 +1973,46 @@ export interface ExtHostNotebookDocumentsAndEditorsShape {
$acceptDocumentAndEditorsDelta(delta: INotebookDocumentsAndEditorsDelta): void;
}
export type NotebookRawContentEventDto =
// notebookCommon.NotebookCellsInitializeEvent<NotebookCellDto>
| {
readonly kind: notebookCommon.NotebookCellsChangeType.ModelChange;
readonly changes: notebookCommon.NotebookCellTextModelSplice<NotebookCellDto>[];
}
| {
readonly kind: notebookCommon.NotebookCellsChangeType.Move;
readonly index: number;
readonly length: number;
readonly newIdx: number;
}
| {
readonly kind: notebookCommon.NotebookCellsChangeType.Output;
readonly index: number;
readonly outputs: NotebookOutputDto[];
}
| {
readonly kind: notebookCommon.NotebookCellsChangeType.OutputItem;
readonly index: number;
readonly outputId: string;
readonly outputItems: NotebookOutputItemDto[];
readonly append: boolean;
}
| notebookCommon.NotebookCellsChangeLanguageEvent
| notebookCommon.NotebookCellsChangeMetadataEvent
| notebookCommon.NotebookCellsChangeInternalMetadataEvent
// | notebookCommon.NotebookDocumentChangeMetadataEvent
// | notebookCommon.NotebookCellContentChangeEvent
// | notebookCommon.NotebookDocumentUnknownChangeEvent
;
export type NotebookCellsChangedEventDto = {
readonly rawEvents: NotebookRawContentEventDto[];
readonly versionId: number;
};
export interface ExtHostNotebookDocumentsShape {
$acceptModelChanged(uriComponents: UriComponents, event: notebookCommon.NotebookCellsChangedEventDto, isDirty: boolean): void;
$acceptModelChanged(uriComponents: UriComponents, event: NotebookCellsChangedEventDto, isDirty: boolean): void;
$acceptDirtyStateChanged(uriComponents: UriComponents, isDirty: boolean): void;
$acceptModelSaved(uriComponents: UriComponents): void;
$acceptDocumentPropertiesChanged(uriComponents: UriComponents, data: INotebookDocumentPropertiesChangeData): void;

View File

@@ -15,14 +15,14 @@ import { assertIsDefined } from 'vs/base/common/types';
import { URI, UriComponents } from 'vs/base/common/uri';
import { IExtensionDescription } from 'vs/platform/extensions/common/extensions';
import { Cache } from 'vs/workbench/api/common/cache';
import { ExtHostNotebookShape, IMainContext, IModelAddedData, INotebookCellStatusBarListDto, INotebookDocumentsAndEditorsDelta, INotebookDocumentShowOptions, INotebookEditorAddData, MainContext, MainThreadNotebookDocumentsShape, MainThreadNotebookEditorsShape, MainThreadNotebookShape } from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostNotebookShape, IMainContext, IModelAddedData, INotebookCellStatusBarListDto, INotebookDocumentsAndEditorsDelta, INotebookDocumentShowOptions, INotebookEditorAddData, MainContext, MainThreadNotebookDocumentsShape, MainThreadNotebookEditorsShape, MainThreadNotebookShape, NotebookDataDto } from 'vs/workbench/api/common/extHost.protocol';
import { CommandsConverter, ExtHostCommands } from 'vs/workbench/api/common/extHostCommands';
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
import { ExtHostDocumentsAndEditors } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import { IExtensionStoragePaths } from 'vs/workbench/api/common/extHostStoragePaths';
import * as typeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import { INotebookExclusiveDocumentFilter, INotebookContributionData, NotebookCellsChangeType, NotebookDataDto } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { INotebookExclusiveDocumentFilter, INotebookContributionData } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import type * as vscode from 'vscode';
import { ExtHostCell, ExtHostNotebookDocument } from './extHostNotebookDocument';
import { ExtHostNotebookEditor } from './extHostNotebookEditor';
@@ -438,7 +438,6 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
for (const modelData of delta.addedDocuments) {
const uri = URI.revive(modelData.uri);
const viewType = modelData.viewType;
if (this._documents.has(uri)) {
throw new Error(`adding EXISTING notebook ${uri} `);
@@ -463,19 +462,10 @@ export class ExtHostNotebookController implements ExtHostNotebookShape {
that._onDidChangeCellExecutionState.fire(event);
}
},
viewType,
modelData.metadata ?? Object.create({}),
uri,
modelData
);
document.acceptModelChanged({
versionId: modelData.versionId,
rawEvents: [{
kind: NotebookCellsChangeType.Initialize,
changes: [[0, 0, modelData.cells]]
}]
}, false);
// add cell document as vscode.TextDocument
addedCellDocuments.push(...modelData.cells.map(cell => ExtHostCell.asModelAddData(document.apiNotebook, cell)));

View File

@@ -6,12 +6,12 @@
import { Schemas } from 'vs/base/common/network';
import { deepFreeze, equals } from 'vs/base/common/objects';
import { URI } from 'vs/base/common/uri';
import { INotebookDocumentPropertiesChangeData, MainThreadNotebookDocumentsShape } from 'vs/workbench/api/common/extHost.protocol';
import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostDocuments } from 'vs/workbench/api/common/extHostDocuments';
import { ExtHostDocumentsAndEditors, IExtHostModelAddedData } from 'vs/workbench/api/common/extHostDocumentsAndEditors';
import * as extHostTypeConverters from 'vs/workbench/api/common/extHostTypeConverters';
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import { CellKind, IMainCellDto, IOutputDto, IOutputItemDto, NotebookCellInternalMetadata, NotebookCellMetadata, NotebookCellsChangedEventDto, NotebookCellsChangeType, NotebookCellsSplice2 } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import * as notebookCommon from 'vs/workbench/contrib/notebook/common/notebookCommon';
import * as vscode from 'vscode';
class RawContentChangeEvent {
@@ -32,7 +32,7 @@ class RawContentChangeEvent {
export class ExtHostCell {
static asModelAddData(notebook: vscode.NotebookDocument, cell: IMainCellDto): IExtHostModelAddedData {
static asModelAddData(notebook: vscode.NotebookDocument, cell: extHostProtocol.NotebookCellDto): IExtHostModelAddedData {
return {
EOL: cell.eol,
lines: cell.source,
@@ -45,20 +45,20 @@ export class ExtHostCell {
}
private _outputs: vscode.NotebookCellOutput[];
private _metadata: NotebookCellMetadata;
private _metadata: notebookCommon.NotebookCellMetadata;
private _previousResult: vscode.NotebookCellExecutionSummary | undefined;
private _internalMetadata: NotebookCellInternalMetadata;
private _internalMetadata: notebookCommon.NotebookCellInternalMetadata;
readonly handle: number;
readonly uri: URI;
readonly cellKind: CellKind;
readonly cellKind: notebookCommon.CellKind;
private _apiCell: vscode.NotebookCell | undefined;
constructor(
readonly notebook: ExtHostNotebookDocument,
private readonly _extHostDocument: ExtHostDocumentsAndEditors,
private readonly _cellData: IMainCellDto,
private readonly _cellData: extHostProtocol.NotebookCellDto,
) {
this.handle = _cellData.handle;
this.uri = URI.revive(_cellData.uri);
@@ -69,7 +69,7 @@ export class ExtHostCell {
this._previousResult = extHostTypeConverters.NotebookCellExecutionSummary.to(_cellData.internalMetadata ?? {});
}
get internalMetadata(): NotebookCellInternalMetadata {
get internalMetadata(): notebookCommon.NotebookCellInternalMetadata {
return this._internalMetadata;
}
@@ -93,11 +93,11 @@ export class ExtHostCell {
return this._apiCell;
}
setOutputs(newOutputs: IOutputDto[]): void {
setOutputs(newOutputs: extHostProtocol.NotebookOutputDto[]): void {
this._outputs = newOutputs.map(extHostTypeConverters.NotebookCellOutput.to);
}
setOutputItems(outputId: string, append: boolean, newOutputItems: IOutputItemDto[]) {
setOutputItems(outputId: string, append: boolean, newOutputItems: extHostProtocol.NotebookOutputItemDto[]) {
const newItems = newOutputItems.map(extHostTypeConverters.NotebookCellOutputItem.to);
const output = this._outputs.find(op => op.id === outputId);
if (output) {
@@ -108,11 +108,11 @@ export class ExtHostCell {
}
}
setMetadata(newMetadata: NotebookCellMetadata): void {
setMetadata(newMetadata: notebookCommon.NotebookCellMetadata): void {
this._metadata = newMetadata;
}
setInternalMetadata(newInternalMetadata: NotebookCellInternalMetadata): void {
setInternalMetadata(newInternalMetadata: notebookCommon.NotebookCellInternalMetadata): void {
this._internalMetadata = newInternalMetadata;
this._previousResult = extHostTypeConverters.NotebookCellExecutionSummary.to(newInternalMetadata);
}
@@ -131,23 +131,30 @@ export class ExtHostNotebookDocument {
private static _handlePool: number = 0;
readonly handle = ExtHostNotebookDocument._handlePool++;
private _cells: ExtHostCell[] = [];
private readonly _cells: ExtHostCell[] = [];
private readonly _notebookType: string;
private _notebook: vscode.NotebookDocument | undefined;
private _metadata: Record<string, any>;
private _versionId: number = 0;
private _isDirty: boolean = false;
private _backup?: vscode.NotebookDocumentBackup;
private _disposed: boolean = false;
constructor(
private readonly _proxy: MainThreadNotebookDocumentsShape,
private readonly _proxy: extHostProtocol.MainThreadNotebookDocumentsShape,
private readonly _textDocumentsAndEditors: ExtHostDocumentsAndEditors,
private readonly _textDocuments: ExtHostDocuments,
private readonly _emitter: INotebookEventEmitter,
private readonly _notebookType: string,
private _metadata: Record<string, any>,
readonly uri: URI,
) { }
data: extHostProtocol.INotebookModelAddedData
) {
this._notebookType = data.viewType;
this._metadata = data.metadata ?? Object.create(null);
this._spliceNotebookCells([[0, 0, data.cells]], true /* init -> no event*/);
this._versionId = data.versionId;
}
dispose() {
this._disposed = true;
@@ -191,32 +198,34 @@ export class ExtHostNotebookDocument {
this._backup = undefined;
}
acceptDocumentPropertiesChanged(data: INotebookDocumentPropertiesChangeData) {
acceptDocumentPropertiesChanged(data: extHostProtocol.INotebookDocumentPropertiesChangeData) {
if (data.metadata) {
this._metadata = { ...this._metadata, ...data.metadata };
}
}
acceptModelChanged(event: NotebookCellsChangedEventDto, isDirty: boolean): void {
acceptDirty(isDirty: boolean): void {
this._isDirty = isDirty;
}
acceptModelChanged(event: extHostProtocol.NotebookCellsChangedEventDto, isDirty: boolean): void {
this._versionId = event.versionId;
this._isDirty = isDirty;
for (const rawEvent of event.rawEvents) {
if (rawEvent.kind === NotebookCellsChangeType.Initialize) {
this._spliceNotebookCells(rawEvent.changes, true);
} if (rawEvent.kind === NotebookCellsChangeType.ModelChange) {
if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.ModelChange) {
this._spliceNotebookCells(rawEvent.changes, false);
} else if (rawEvent.kind === NotebookCellsChangeType.Move) {
} else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.Move) {
this._moveCell(rawEvent.index, rawEvent.newIdx);
} else if (rawEvent.kind === NotebookCellsChangeType.Output) {
} else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.Output) {
this._setCellOutputs(rawEvent.index, rawEvent.outputs);
} else if (rawEvent.kind === NotebookCellsChangeType.OutputItem) {
} else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.OutputItem) {
this._setCellOutputItems(rawEvent.index, rawEvent.outputId, rawEvent.append, rawEvent.outputItems);
} else if (rawEvent.kind === NotebookCellsChangeType.ChangeLanguage) {
} else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.ChangeLanguage) {
this._changeCellLanguage(rawEvent.index, rawEvent.language);
} else if (rawEvent.kind === NotebookCellsChangeType.ChangeCellMetadata) {
} else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.ChangeCellMetadata) {
this._changeCellMetadata(rawEvent.index, rawEvent.metadata);
} else if (rawEvent.kind === NotebookCellsChangeType.ChangeCellInternalMetadata) {
} else if (rawEvent.kind === notebookCommon.NotebookCellsChangeType.ChangeCellInternalMetadata) {
this._changeCellInternalMetadata(rawEvent.index, rawEvent.internalMetadata);
}
}
@@ -261,7 +270,7 @@ export class ExtHostNotebookDocument {
return this._proxy.$trySaveNotebook(this.uri);
}
private _spliceNotebookCells(splices: NotebookCellsSplice2[], initialization: boolean): void {
private _spliceNotebookCells(splices: notebookCommon.NotebookCellTextModelSplice<extHostProtocol.NotebookCellDto>[], initialization: boolean): void {
if (this._disposed) {
return;
}
@@ -317,13 +326,13 @@ export class ExtHostNotebookDocument {
}));
}
private _setCellOutputs(index: number, outputs: IOutputDto[]): void {
private _setCellOutputs(index: number, outputs: extHostProtocol.NotebookOutputDto[]): void {
const cell = this._cells[index];
cell.setOutputs(outputs);
this._emitter.emitCellOutputsChange(deepFreeze({ document: this.apiNotebook, cells: [cell.apiCell] }));
}
private _setCellOutputItems(index: number, outputId: string, append: boolean, outputItems: IOutputItemDto[]): void {
private _setCellOutputItems(index: number, outputId: string, append: boolean, outputItems: extHostProtocol.NotebookOutputItemDto[]): void {
const cell = this._cells[index];
cell.setOutputItems(outputId, append, outputItems);
this._emitter.emitCellOutputsChange(deepFreeze({ document: this.apiNotebook, cells: [cell.apiCell] }));
@@ -336,7 +345,7 @@ export class ExtHostNotebookDocument {
}
}
private _changeCellMetadata(index: number, newMetadata: NotebookCellMetadata): void {
private _changeCellMetadata(index: number, newMetadata: notebookCommon.NotebookCellMetadata): void {
const cell = this._cells[index];
const originalExtMetadata = cell.apiCell.metadata;
@@ -348,7 +357,7 @@ export class ExtHostNotebookDocument {
}
}
private _changeCellInternalMetadata(index: number, newInternalMetadata: NotebookCellInternalMetadata): void {
private _changeCellInternalMetadata(index: number, newInternalMetadata: notebookCommon.NotebookCellInternalMetadata): void {
const cell = this._cells[index];
const originalInternalMetadata = cell.internalMetadata;

View File

@@ -6,12 +6,11 @@
import { Emitter } from 'vs/base/common/event';
import { URI, UriComponents } from 'vs/base/common/uri';
import { ILogService } from 'vs/platform/log/common/log';
import { ExtHostNotebookDocumentsShape, INotebookDocumentPropertiesChangeData } from 'vs/workbench/api/common/extHost.protocol';
import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol';
import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
import { NotebookCellsChangedEventDto } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import type * as vscode from 'vscode';
export class ExtHostNotebookDocuments implements ExtHostNotebookDocumentsShape {
export class ExtHostNotebookDocuments implements extHostProtocol.ExtHostNotebookDocumentsShape {
private readonly _onDidChangeNotebookDocumentMetadata = new Emitter<vscode.NotebookDocumentMetadataChangeEvent>();
readonly onDidChangeNotebookDocumentMetadata = this._onDidChangeNotebookDocumentMetadata.event;
@@ -24,14 +23,14 @@ export class ExtHostNotebookDocuments implements ExtHostNotebookDocumentsShape {
private readonly _notebooksAndEditors: ExtHostNotebookController,
) { }
$acceptModelChanged(uri: UriComponents, event: NotebookCellsChangedEventDto, isDirty: boolean): void {
$acceptModelChanged(uri: UriComponents, event: extHostProtocol.NotebookCellsChangedEventDto, isDirty: boolean): void {
const document = this._notebooksAndEditors.getNotebookDocument(URI.revive(uri));
document.acceptModelChanged(event, isDirty);
}
$acceptDirtyStateChanged(uri: UriComponents, isDirty: boolean): void {
const document = this._notebooksAndEditors.getNotebookDocument(URI.revive(uri));
document.acceptModelChanged({ rawEvents: [], versionId: document.apiNotebook.version }, isDirty);
document.acceptDirty(isDirty);
}
$acceptModelSaved(uri: UriComponents): void {
@@ -39,7 +38,7 @@ export class ExtHostNotebookDocuments implements ExtHostNotebookDocumentsShape {
this._onDidSaveNotebookDocument.fire(document.apiNotebook);
}
$acceptDocumentPropertiesChanged(uri: UriComponents, data: INotebookDocumentPropertiesChangeData): void {
$acceptDocumentPropertiesChanged(uri: UriComponents, data: extHostProtocol.INotebookDocumentPropertiesChangeData): void {
this._logService.debug('ExtHostNotebook#$acceptDocumentPropertiesChanged', uri.path, data);
const document = this._notebooksAndEditors.getNotebookDocument(URI.revive(uri));
document.acceptDocumentPropertiesChanged(data);

View File

@@ -3,17 +3,17 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { MainThreadNotebookEditorsShape } from 'vs/workbench/api/common/extHost.protocol';
import { ICellEditOperationDto, MainThreadNotebookEditorsShape } from 'vs/workbench/api/common/extHost.protocol';
import * as extHostTypes from 'vs/workbench/api/common/extHostTypes';
import * as extHostConverter from 'vs/workbench/api/common/extHostTypeConverters';
import { CellEditType, ICellEditOperation, ICellReplaceEdit } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellEditType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import * as vscode from 'vscode';
import { ExtHostNotebookDocument } from './extHostNotebookDocument';
import { illegalArgument } from 'vs/base/common/errors';
interface INotebookEditData {
documentVersionId: number;
cellEdits: ICellEditOperation[];
cellEdits: ICellEditOperationDto[];
}
class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit {
@@ -21,7 +21,7 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit {
private readonly _documentVersionId: number;
private _finalized: boolean = false;
private _collectedEdits: ICellEditOperation[] = [];
private _collectedEdits: ICellEditOperationDto[] = [];
constructor(documentVersionId: number) {
this._documentVersionId = documentVersionId;
@@ -52,7 +52,7 @@ class NotebookEditorCellEditBuilder implements vscode.NotebookEditorEdit {
replaceCellMetadata(index: number, metadata: Record<string, any>): void {
this._throwIfFinalized();
this._collectedEdits.push({
editType: CellEditType.Metadata,
editType: CellEditType.PartialMetadata,
index,
metadata
});
@@ -174,7 +174,7 @@ export class ExtHostNotebookEditor {
return Promise.resolve(true);
}
const compressedEdits: ICellEditOperation[] = [];
const compressedEdits: ICellEditOperationDto[] = [];
let compressedEditsIndex = -1;
for (let i = 0; i < editData.cellEdits.length; i++) {
@@ -190,8 +190,8 @@ export class ExtHostNotebookEditor {
const edit = editData.cellEdits[i];
if (prev.editType === CellEditType.Replace && edit.editType === CellEditType.Replace) {
if (prev.index === edit.index) {
prev.cells.push(...(editData.cellEdits[i] as ICellReplaceEdit).cells);
prev.count += (editData.cellEdits[i] as ICellReplaceEdit).count;
prev.cells.push(...(editData.cellEdits[i] as any).cells);
prev.count += (editData.cellEdits[i] as any).count;
continue;
}
}

View File

@@ -5,7 +5,7 @@
import { Emitter } from 'vs/base/common/event';
import { Disposable, DisposableStore } from 'vs/base/common/lifecycle';
import { ExtHostNotebookKernelsShape, IMainContext, INotebookKernelDto2, MainContext, MainThreadNotebookKernelsShape } from 'vs/workbench/api/common/extHost.protocol';
import { CellExecuteEditDto, ExtHostNotebookKernelsShape, IMainContext, INotebookKernelDto2, MainContext, MainThreadNotebookKernelsShape, NotebookOutputDto } from 'vs/workbench/api/common/extHost.protocol';
import * as vscode from 'vscode';
import { ExtHostNotebookController } from 'vs/workbench/api/common/extHostNotebook';
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
@@ -16,7 +16,7 @@ import { asWebviewUri } from 'vs/workbench/api/common/shared/webview';
import { ResourceMap } from 'vs/base/common/map';
import { timeout } from 'vs/base/common/async';
import { ExtHostCell, ExtHostNotebookDocument } from 'vs/workbench/api/common/extHostNotebookDocument';
import { CellEditType, IImmediateCellEditOperation, IOutputDto, NotebookCellExecutionState, NullablePartialNotebookCellInternalMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellEditType, NotebookCellExecutionState, NullablePartialNotebookCellInternalMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CancellationTokenSource } from 'vs/base/common/cancellation';
import { asArray } from 'vs/base/common/arrays';
import { ILogService } from 'vs/platform/log/common/log';
@@ -332,7 +332,7 @@ class NotebookCellExecutionTask extends Disposable {
private readonly _tokenSource = this._register(new CancellationTokenSource());
private readonly _collector: TimeoutBasedCollector<IImmediateCellEditOperation>;
private readonly _collector: TimeoutBasedCollector<CellExecuteEditDto>;
private _executionOrder: number | undefined;
@@ -356,11 +356,11 @@ class NotebookCellExecutionTask extends Disposable {
this._tokenSource.cancel();
}
private async applyEditSoon(edit: IImmediateCellEditOperation): Promise<void> {
private async applyEditSoon(edit: CellExecuteEditDto): Promise<void> {
await this._collector.addItem(edit);
}
private async applyEdits(edits: IImmediateCellEditOperation[]): Promise<void> {
private async applyEdits(edits: CellExecuteEditDto[]): Promise<void> {
return this._proxy.$applyExecutionEdits(this._document.uri, edits);
}
@@ -375,8 +375,11 @@ class NotebookCellExecutionTask extends Disposable {
}
private mixinMetadata(mixinMetadata: NullablePartialNotebookCellInternalMetadata) {
const edit: IImmediateCellEditOperation = { editType: CellEditType.PartialInternalMetadata, handle: this._cell.handle, internalMetadata: mixinMetadata };
this.applyEdits([edit]);
this.applyEdits([{
editType: CellEditType.PartialInternalMetadata,
handle: this._cell.handle,
internalMetadata: mixinMetadata
}]);
}
private cellIndexToHandle(cellOrCellIndex: vscode.NotebookCell | undefined): number {
@@ -390,7 +393,7 @@ class NotebookCellExecutionTask extends Disposable {
return cell.handle;
}
private validateAndConvertOutputs(items: vscode.NotebookCellOutput[]): IOutputDto[] {
private validateAndConvertOutputs(items: vscode.NotebookCellOutput[]): NotebookOutputDto[] {
return items.map(output => {
const newOutput = NotebookCellOutput.ensureUniqueMimeTypes(output.items, true);
if (newOutput === output.items) {

View File

@@ -548,33 +548,6 @@ export namespace WorkspaceEdit {
notebookVersionId: extHostNotebooks?.getNotebookDocument(entry.uri, true)?.apiNotebook.version
});
} else if (entry._type === types.FileEditType.CellOutput) {
if (entry.newOutputs) {
result.edits.push({
_type: extHostProtocol.WorkspaceEditType.Cell,
metadata: entry.metadata,
resource: entry.uri,
edit: {
editType: notebooks.CellEditType.Output,
index: entry.index,
append: entry.append,
outputs: entry.newOutputs.map(NotebookCellOutput.from)
}
});
}
// todo@joh merge metadata and output edit?
if (entry.newMetadata) {
result.edits.push({
_type: extHostProtocol.WorkspaceEditType.Cell,
metadata: entry.metadata,
resource: entry.uri,
edit: {
editType: notebooks.CellEditType.PartialMetadata,
index: entry.index,
metadata: entry.newMetadata
}
});
}
} else if (entry._type === types.FileEditType.CellReplace) {
result.edits.push({
_type: extHostProtocol.WorkspaceEditType.Cell,
@@ -588,18 +561,6 @@ export namespace WorkspaceEdit {
cells: entry.cells.map(NotebookCellData.from)
}
});
} else if (entry._type === types.FileEditType.CellOutputItem) {
result.edits.push({
_type: extHostProtocol.WorkspaceEditType.Cell,
metadata: entry.metadata,
resource: entry.uri,
edit: {
editType: notebooks.CellEditType.OutputItems,
outputId: entry.outputId,
items: entry.newOutputItems?.map(NotebookCellOutputItem.from) || [],
append: entry.append
}
});
}
}
}
@@ -1458,8 +1419,8 @@ export namespace NotebookCellKind {
export namespace NotebookData {
export function from(data: vscode.NotebookData): notebooks.NotebookDataDto {
const res: notebooks.NotebookDataDto = {
export function from(data: vscode.NotebookData): extHostProtocol.NotebookDataDto {
const res: extHostProtocol.NotebookDataDto = {
metadata: data.metadata ?? Object.create(null),
cells: [],
};
@@ -1470,7 +1431,7 @@ export namespace NotebookData {
return res;
}
export function to(data: notebooks.NotebookDataDto): vscode.NotebookData {
export function to(data: extHostProtocol.NotebookDataDto): vscode.NotebookData {
const res = new types.NotebookData(
data.cells.map(NotebookCellData.to),
);
@@ -1483,7 +1444,7 @@ export namespace NotebookData {
export namespace NotebookCellData {
export function from(data: vscode.NotebookCellData): notebooks.ICellDto2 {
export function from(data: vscode.NotebookCellData): extHostProtocol.NotebookCellDataDto {
return {
cellKind: NotebookCellKind.from(data.kind),
language: data.languageId,
@@ -1494,7 +1455,7 @@ export namespace NotebookCellData {
};
}
export function to(data: notebooks.ICellDto2): vscode.NotebookCellData {
export function to(data: extHostProtocol.NotebookCellDataDto): vscode.NotebookCellData {
return new types.NotebookCellData(
NotebookCellKind.to(data.cellKind),
data.source,
@@ -1507,29 +1468,29 @@ export namespace NotebookCellData {
}
export namespace NotebookCellOutputItem {
export function from(item: types.NotebookCellOutputItem): notebooks.IOutputItemDto {
export function from(item: types.NotebookCellOutputItem): extHostProtocol.NotebookOutputItemDto {
return {
mime: item.mime,
valueBytes: Array.from(item.data), //todo@jrieken this HACKY and SLOW... hoist VSBuffer instead
};
}
export function to(item: notebooks.IOutputItemDto): types.NotebookCellOutputItem {
export function to(item: extHostProtocol.NotebookOutputItemDto): types.NotebookCellOutputItem {
return new types.NotebookCellOutputItem(new Uint8Array(item.valueBytes), item.mime);
}
}
export namespace NotebookCellOutput {
export function from(output: vscode.NotebookCellOutput): notebooks.IOutputDto {
export function from(output: vscode.NotebookCellOutput): extHostProtocol.NotebookOutputDto {
return {
outputId: output.id,
outputs: output.items.map(NotebookCellOutputItem.from),
items: output.items.map(NotebookCellOutputItem.from),
metadata: output.metadata
};
}
export function to(output: notebooks.IOutputDto): vscode.NotebookCellOutput {
const items = output.outputs.map(NotebookCellOutputItem.to);
export function to(output: extHostProtocol.NotebookOutputDto): vscode.NotebookCellOutput {
const items = output.items.map(NotebookCellOutputItem.to);
return new types.NotebookCellOutput(items, output.outputId, output.metadata);
}
}

View File

@@ -15,7 +15,7 @@ import { generateUuid } from 'vs/base/common/uuid';
import { FileSystemProviderErrorCode, markAsFileSystemProviderError } from 'vs/platform/files/common/files';
import { RemoteAuthorityResolverErrorCode } from 'vs/platform/remote/common/remoteAuthorityResolver';
import { getPrivateApiFor, ExtHostTestItemEventType, IExtHostTestItemApi } from 'vs/workbench/api/common/extHostTestingPrivateApi';
import { CellEditType, ICellEditOperation } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { CellEditType, ICellPartialMetadataEdit, IDocumentMetadataEdit } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import type * as vscode from 'vscode';
function es5ClassCompat(target: Function): any {
@@ -588,9 +588,7 @@ export const enum FileEditType {
File = 1,
Text = 2,
Cell = 3,
CellOutput = 4,
CellReplace = 5,
CellOutputItem = 6
}
export interface IFileOperation {
@@ -611,7 +609,7 @@ export interface IFileTextEdit {
export interface IFileCellEdit {
_type: FileEditType.Cell;
uri: URI;
edit?: ICellEditOperation;
edit?: ICellPartialMetadataEdit | IDocumentMetadataEdit;
notebookMetadata?: Record<string, any>;
metadata?: vscode.WorkspaceEditEntryMetadata;
}
@@ -625,28 +623,8 @@ export interface ICellEdit {
cells: vscode.NotebookCellData[];
}
export interface ICellOutputEdit {
_type: FileEditType.CellOutput;
uri: URI;
index: number;
append: boolean;
newOutputs?: NotebookCellOutput[];
newMetadata?: Record<string, any>;
metadata?: vscode.WorkspaceEditEntryMetadata;
}
export interface ICellOutputItemsEdit {
_type: FileEditType.CellOutputItem;
uri: URI;
index: number;
outputId: string;
append: boolean;
newOutputItems?: NotebookCellOutputItem[];
metadata?: vscode.WorkspaceEditEntryMetadata;
}
type WorkspaceEditEntry = IFileOperation | IFileTextEdit | IFileCellEdit | ICellEdit | ICellOutputEdit | ICellOutputItemsEdit;
type WorkspaceEditEntry = IFileOperation | IFileTextEdit | IFileCellEdit | ICellEdit;
@es5ClassCompat
export class WorkspaceEdit implements vscode.WorkspaceEdit {