Skip to content

Commit

Permalink
started reorganizing Types from notebook-common
Browse files Browse the repository at this point in the history
and type converters

Signed-off-by: Jonah Iden <jonah.iden@typefox.io>
  • Loading branch information
jonah-iden committed Oct 24, 2023
1 parent 75aef4e commit c8b9969
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 247 deletions.
106 changes: 106 additions & 0 deletions packages/notebook/src/browser/notebook-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// *****************************************************************************
// Copyright (C) 2023 TypeFox and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// http://www.eclipse.org/legal/epl-2.0.
//
// This Source Code may also be made available under the following Secondary
// Licenses when the conditions for such availability set forth in the Eclipse
// Public License v. 2.0 are satisfied: GNU General Public License, version 2
// with the GNU Classpath Exception which is available at
// https://www.gnu.org/software/classpath/license.html.
//
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
// *****************************************************************************

import {
CellData, CellOutput, CellOutputItem, CellRange, NotebookCellContentChangeEvent,
NotebookCellsChangeInternalMetadataEvent,
NotebookCellsChangeLanguageEvent,
NotebookCellsChangeMetadataEvent,
NotebookCellsChangeType, NotebookCellTextModelSplice, NotebookDocumentMetadata
} from '../common';
import { NotebookCell } from './view-model/notebook-cell-model';

export interface NotebookTextModelChangedEvent {
readonly rawEvents: NotebookContentChangedEvent[];
// readonly versionId: number;
readonly synchronous?: boolean;
readonly endSelectionState?: SelectionState;
};

export type NotebookContentChangedEvent = (NotebookCellsInitializeEvent<NotebookCell> | NotebookDocumentChangeMetadataEvent | NotebookCellContentChangeEvent |
NotebookCellsModelChangedEvent<NotebookCell> | NotebookCellsModelMoveEvent<NotebookCell> | NotebookOutputChangedEvent | NotebookOutputItemChangedEvent |
NotebookCellsChangeLanguageEvent | NotebookCellsChangeMetadataEvent |
NotebookCellsChangeInternalMetadataEvent | NotebookDocumentUnknownChangeEvent); // & { transient: boolean };

export interface NotebookCellsInitializeEvent<T> {
readonly kind: NotebookCellsChangeType.Initialize;
readonly changes: NotebookCellTextModelSplice<T>[];
}

export interface NotebookDocumentChangeMetadataEvent {
readonly kind: NotebookCellsChangeType.ChangeDocumentMetadata;
readonly metadata: NotebookDocumentMetadata;
}

export interface NotebookCellsModelChangedEvent<T> {
readonly kind: NotebookCellsChangeType.ModelChange;
readonly changes: NotebookCellTextModelSplice<T>[];
}

export interface NotebookModelWillAddRemoveEvent {
readonly rawEvent: NotebookCellsModelChangedEvent<CellData>;
};

export interface NotebookCellsModelMoveEvent<T> {
readonly kind: NotebookCellsChangeType.Move;
readonly index: number;
readonly length: number;
readonly newIdx: number;
readonly cells: T[];
}

export interface NotebookOutputChangedEvent {
readonly kind: NotebookCellsChangeType.Output;
readonly index: number;
readonly outputs: CellOutput[];
readonly append: boolean;
}

export interface NotebookOutputItemChangedEvent {
readonly kind: NotebookCellsChangeType.OutputItem;
readonly index: number;
readonly outputId: string;
readonly outputItems: CellOutputItem[];
readonly append: boolean;
}

export interface NotebookDocumentUnknownChangeEvent {
readonly kind: NotebookCellsChangeType.Unknown;
}

export enum SelectionStateType {
Handle = 0,
Index = 1
}

export interface SelectionHandleState {
kind: SelectionStateType.Handle;
primary: number | null;
selections: number[];
}

export interface SelectionIndexState {
kind: SelectionStateType.Index;
focus: CellRange;
selections: CellRange[];
}

export type SelectionState = SelectionHandleState | SelectionIndexState;

export interface NotebookModelWillAddRemoveEvent {
readonly newCellIds?: number[];
readonly rawEvent: NotebookCellsModelChangedEvent<CellData>;
};
19 changes: 18 additions & 1 deletion packages/notebook/src/browser/view-model/notebook-cell-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { MonacoEditorModel } from '@theia/monaco/lib/browser/monaco-editor-model
import { MonacoTextModelService } from '@theia/monaco/lib/browser/monaco-text-model-service';
import {
CellInternalMetadataChangedEvent, CellKind, NotebookCellCollapseState, NotebookCellInternalMetadata,
NotebookCellMetadata, NotebookCellOutputsSplice, CellOutput, CellData, NotebookCell, CellOutputItem
NotebookCellMetadata, NotebookCellOutputsSplice, CellOutput, CellData, CellOutputItem
} from '../../common';
import { NotebookCellOutputModel } from './notebook-cell-output-model';

Expand All @@ -51,6 +51,23 @@ interface NotebookCellContextManager {
onDidChangeContext: Event<ContextKeyChangeEvent>;
}

export interface NotebookCell {
readonly uri: URI;
handle: number;
language: string;
cellKind: CellKind;
outputs: CellOutput[];
metadata: NotebookCellMetadata;
internalMetadata: NotebookCellInternalMetadata;
text: string;
onDidChangeOutputs?: Event<NotebookCellOutputsSplice>;
onDidChangeOutputItems?: Event<CellOutput>;
onDidChangeLanguage: Event<string>;
onDidChangeMetadata: Event<void>;
onDidChangeInternalMetadata: Event<CellInternalMetadataChangedEvent>;

}

const NotebookCellModelProps = Symbol('NotebookModelProps');
export interface NotebookCellModelProps {
readonly uri: URI,
Expand Down
5 changes: 3 additions & 2 deletions packages/notebook/src/browser/view-model/notebook-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import {
CellData,
CellEditOperation, CellEditType, CellUri, NotebookCellInternalMetadata,
NotebookCellsChangeType, NotebookCellTextModelSplice, NotebookData,
NotebookDocumentMetadata, NotebookModelWillAddRemoveEvent,
NullablePartialNotebookCellInternalMetadata, NotebookContentChangedEvent
NotebookDocumentMetadata,
NullablePartialNotebookCellInternalMetadata
} from '../../common';
import { NotebookContentChangedEvent, NotebookModelWillAddRemoveEvent } from '../notebook-types';
import { NotebookSerializer } from '../service/notebook-service';
import { FileService } from '@theia/filesystem/lib/browser/file-service';
import { NotebookCellModel, NotebookCellModelFactory } from './notebook-cell-model';
Expand Down
87 changes: 0 additions & 87 deletions packages/notebook/src/common/notebook-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { CancellationToken, Command, Event, URI } from '@theia/core';
import { MarkdownString } from '@theia/core/lib/common/markdown-rendering/markdown-string';
import { BinaryBuffer } from '@theia/core/lib/common/buffer';
import { UriComponents } from '@theia/core/lib/common/uri';
import { CellRange } from './notebook-range';

export enum CellKind {
Markup = 1,
Expand Down Expand Up @@ -88,23 +87,6 @@ export interface NotebookCellCollapseState {
outputCollapsed?: boolean;
}

export interface NotebookCell {
readonly uri: URI;
handle: number;
language: string;
cellKind: CellKind;
outputs: CellOutput[];
metadata: NotebookCellMetadata;
internalMetadata: NotebookCellInternalMetadata;
text: string;
onDidChangeOutputs?: Event<NotebookCellOutputsSplice>;
onDidChangeOutputItems?: Event<CellOutput>;
onDidChangeLanguage: Event<string>;
onDidChangeMetadata: Event<void>;
onDidChangeInternalMetadata: Event<CellInternalMetadataChangedEvent>;

}

export interface CellData {
source: string;
language: string;
Expand Down Expand Up @@ -182,62 +164,12 @@ export enum NotebookCellsChangeType {
Unknown = 100
}

export enum SelectionStateType {
Handle = 0,
Index = 1
}
export interface SelectionHandleState {
kind: SelectionStateType.Handle;
primary: number | null;
selections: number[];
}

export interface SelectionIndexState {
kind: SelectionStateType.Index;
focus: CellRange;
selections: CellRange[];
}

export type SelectionState = SelectionHandleState | SelectionIndexState;

export interface NotebookCellsInitializeEvent<T> {
readonly kind: NotebookCellsChangeType.Initialize;
readonly changes: NotebookCellTextModelSplice<T>[];
}

export interface NotebookCellsChangeLanguageEvent {
readonly kind: NotebookCellsChangeType.ChangeCellLanguage;
readonly index: number;
readonly language: string;
}

export interface NotebookCellsModelChangedEvent<T> {
readonly kind: NotebookCellsChangeType.ModelChange;
readonly changes: NotebookCellTextModelSplice<T>[];
}

export interface NotebookCellsModelMoveEvent<T> {
readonly kind: NotebookCellsChangeType.Move;
readonly index: number;
readonly length: number;
readonly newIdx: number;
readonly cells: T[];
}

export interface NotebookOutputChangedEvent {
readonly kind: NotebookCellsChangeType.Output;
readonly index: number;
readonly outputs: CellOutput[];
readonly append: boolean;
}

export interface NotebookOutputItemChangedEvent {
readonly kind: NotebookCellsChangeType.OutputItem;
readonly index: number;
readonly outputId: string;
readonly outputItems: CellOutputItem[];
readonly append: boolean;
}
export interface NotebookCellsChangeMetadataEvent {
readonly kind: NotebookCellsChangeType.ChangeCellMetadata;
readonly index: number;
Expand All @@ -250,30 +182,11 @@ export interface NotebookCellsChangeInternalMetadataEvent {
readonly internalMetadata: NotebookCellInternalMetadata;
}

export interface NotebookDocumentChangeMetadataEvent {
readonly kind: NotebookCellsChangeType.ChangeDocumentMetadata;
readonly metadata: NotebookDocumentMetadata;
}

export interface NotebookDocumentUnknownChangeEvent {
readonly kind: NotebookCellsChangeType.Unknown;
}

export interface NotebookCellContentChangeEvent {
readonly kind: NotebookCellsChangeType.ChangeCellContent;
readonly index: number;
}

export type NotebookContentChangedEvent = (NotebookCellsInitializeEvent<NotebookCell> | NotebookDocumentChangeMetadataEvent | NotebookCellContentChangeEvent |
NotebookCellsModelChangedEvent<NotebookCell> | NotebookCellsModelMoveEvent<NotebookCell> | NotebookOutputChangedEvent | NotebookOutputItemChangedEvent |
NotebookCellsChangeLanguageEvent | NotebookCellsChangeMetadataEvent |
NotebookCellsChangeInternalMetadataEvent | NotebookDocumentUnknownChangeEvent); // & { transient: boolean };

export interface NotebookModelWillAddRemoveEvent {
readonly newCellIds?: number[];
readonly rawEvent: NotebookCellsModelChangedEvent<CellData>;
};

export enum NotebookCellExecutionState {
Unconfirmed = 1,
Pending = 2,
Expand Down
58 changes: 24 additions & 34 deletions packages/plugin-ext/src/main/browser/notebooks/notebook-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { OS } from '@theia/core';
import * as notebookCommon from '@theia/notebook/lib/common';
import { NotebookCellModel } from '@theia/notebook/lib/browser/view-model/notebook-cell-model';
import * as rpc from '../../../common';
import { CellExecutionUpdateType } from '@theia/notebook/lib/common';
import { CellExecuteUpdate, CellExecutionComplete } from '@theia/notebook/lib/browser';

export namespace NotebookDto {

Expand Down Expand Up @@ -102,40 +104,28 @@ export namespace NotebookDto {
};
}

// export function fromCellExecuteUpdateDto(data: extHostProtocol.ICellExecuteUpdateDto): ICellExecuteUpdate {
// if (data.editType === CellExecutionUpdateType.Output) {
// return {
// editType: data.editType,
// cellHandle: data.cellHandle,
// append: data.append,
// outputs: data.outputs.map(fromNotebookOutputDto)
// };
// } else if (data.editType === CellExecutionUpdateType.OutputItems) {
// return {
// editType: data.editType,
// append: data.append,
// outputId: data.outputId,
// items: data.items.map(fromNotebookOutputItemDto)
// };
// } else {
// return data;
// }
// }
export function fromCellExecuteUpdateDto(data: rpc.CellExecuteUpdateDto): CellExecuteUpdate {
if (data.editType === CellExecutionUpdateType.Output) {
return {
editType: data.editType,
cellHandle: data.cellHandle,
append: data.append,
outputs: data.outputs.map(fromNotebookOutputDto)
};
} else if (data.editType === CellExecutionUpdateType.OutputItems) {
return {
editType: data.editType,
outputId: data.outputId,
append: data.append,
items: data.items.map(fromNotebookOutputItemDto)
};
} else {
return data;
}
}

// export function fromCellExecuteCompleteDto(data: extHostProtocol.ICellExecutionCompleteDto): ICellExecutionComplete {
// return data;
// }
export function fromCellExecuteCompleteDto(data: rpc.CellExecutionCompleteDto): CellExecutionComplete {
return data;
}

// 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;
// }
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { CellExecution, NotebookExecutionStateService, NotebookKernelChangeEvent
import { combinedDisposable } from '@theia/monaco-editor-core/esm/vs/base/common/lifecycle';
import { interfaces } from '@theia/core/shared/inversify';
import { NotebookKernelSourceAction } from '@theia/notebook/lib/common';
import { NotebookDto } from '../../../plugin/type-converters';
import { NotebookDto } from './notebook-dto';

abstract class NotebookKernel {
private readonly onDidChangeEmitter = new Emitter<NotebookKernelChangeEvent>();
Expand Down
Loading

0 comments on commit c8b9969

Please sign in to comment.