Skip to content

Commit 35b84e2

Browse files
committed
less use of notebooktextmodel.
1 parent f24856d commit 35b84e2

File tree

7 files changed

+21
-16
lines changed

7 files changed

+21
-16
lines changed

src/vs/workbench/api/browser/mainThreadNotebookDocuments.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { DisposableStore, dispose } from 'vs/base/common/lifecycle';
77
import { ResourceMap } from 'vs/base/common/map';
88
import { URI, UriComponents } from 'vs/base/common/uri';
99
import { BoundModelReferenceCollection } from 'vs/workbench/api/browser/mainThreadDocuments';
10-
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
1110
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
1211
import { NotebookCellsChangeType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
1312
import { INotebookEditorModelResolverService } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverService';
@@ -62,7 +61,7 @@ export class MainThreadNotebookDocuments implements MainThreadNotebookDocumentsS
6261
case NotebookCellsChangeType.ModelChange:
6362
eventDto.rawEvents.push({
6463
kind: e.kind,
65-
changes: e.changes.map(diff => [diff[0], diff[1], diff[2].map(cell => NotebookDto.toNotebookCellDto(cell as NotebookCellTextModel))] as [number, number, NotebookCellDto[]])
64+
changes: e.changes.map(diff => [diff[0], diff[1], diff[2].map(cell => NotebookDto.toNotebookCellDto(cell))] as [number, number, NotebookCellDto[]])
6665
});
6766
break;
6867
case NotebookCellsChangeType.Move:

src/vs/workbench/api/browser/mainThreadNotebookDto.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import * as extHostProtocol from 'vs/workbench/api/common/extHost.protocol';
7-
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
87
import * as notebookCommon from 'vs/workbench/contrib/notebook/common/notebookCommon';
98
import { CellExecutionUpdateType } from 'vs/workbench/contrib/notebook/common/notebookExecutionService';
109
import { ICellExecuteUpdate, ICellExecutionComplete } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
@@ -79,7 +78,7 @@ export namespace NotebookDto {
7978
};
8079
}
8180

82-
export function toNotebookCellDto(cell: NotebookCellTextModel): extHostProtocol.NotebookCellDto {
81+
export function toNotebookCellDto(cell: notebookCommon.ICell): extHostProtocol.NotebookCellDto {
8382
return {
8483
handle: cell.handle,
8584
uri: cell.uri,

src/vs/workbench/contrib/notebook/browser/diff/diffElementViewModel.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { DiffEditorWidget } from 'vs/editor/browser/widget/diffEditorWidget';
1111
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
1212
import { hash } from 'vs/base/common/hash';
1313
import { toFormattedString } from 'vs/base/common/jsonFormatter';
14-
import { ICellOutput, IOutputDto, IOutputItemDto, NotebookCellMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
14+
import { ICellOutput, INotebookTextModel, IOutputDto, IOutputItemDto, NotebookCellMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
1515
import { DiffNestedCellViewModel } from 'vs/workbench/contrib/notebook/browser/diff/diffNestedCellViewModel';
1616
import { URI } from 'vs/base/common/uri';
1717
import { NotebookDiffEditorEventDispatcher, NotebookDiffViewEventType } from 'vs/workbench/contrib/notebook/browser/diff/eventDispatcher';
@@ -117,7 +117,7 @@ export abstract class DiffElementViewModelBase extends Disposable {
117117
private _metadataEditorViewState: editorCommon.ICodeEditorViewState | editorCommon.IDiffEditorViewState | null = null;
118118

119119
constructor(
120-
readonly mainDocumentTextModel: NotebookTextModel,
120+
readonly mainDocumentTextModel: INotebookTextModel,
121121
readonly original: DiffNestedCellViewModel | undefined,
122122
readonly modified: DiffNestedCellViewModel | undefined,
123123
readonly type: 'unchanged' | 'insert' | 'delete' | 'modified',
@@ -645,7 +645,7 @@ function outputsEqual(original: ICellOutput[], modified: ICellOutput[]) {
645645
return OutputComparison.Unchanged;
646646
}
647647

648-
export function getFormattedMetadataJSON(documentTextModel: NotebookTextModel, metadata: NotebookCellMetadata, language?: string) {
648+
export function getFormattedMetadataJSON(documentTextModel: INotebookTextModel, metadata: NotebookCellMetadata, language?: string) {
649649
let filteredMetadata: { [key: string]: any } = {};
650650

651651
if (documentTextModel) {

src/vs/workbench/contrib/notebook/browser/notebook.contribution.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEd
2929
import { isCompositeNotebookEditorInput, NotebookEditorInput, NotebookEditorInputOptions } from 'vs/workbench/contrib/notebook/common/notebookEditorInput';
3030
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
3131
import { NotebookService } from 'vs/workbench/contrib/notebook/browser/notebookServiceImpl';
32-
import { CellKind, CellUri, IResolvedNotebookEditorModel, NotebookDocumentBackupData, NotebookWorkingCopyTypeIdentifier, NotebookSetting, ICellOutput } from 'vs/workbench/contrib/notebook/common/notebookCommon';
32+
import { CellKind, CellUri, IResolvedNotebookEditorModel, NotebookDocumentBackupData, NotebookWorkingCopyTypeIdentifier, NotebookSetting, ICellOutput, ICell } from 'vs/workbench/contrib/notebook/common/notebookCommon';
3333
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
3434
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
3535
import { INotebookEditorModelResolverService } from 'vs/workbench/contrib/notebook/common/notebookEditorModelResolverService';
@@ -99,7 +99,6 @@ import { NotebookExecutionService } from 'vs/workbench/contrib/notebook/browser/
9999
import { INotebookExecutionService } from 'vs/workbench/contrib/notebook/common/notebookExecutionService';
100100
import { INotebookKeymapService } from 'vs/workbench/contrib/notebook/common/notebookKeymapService';
101101
import { NotebookKeymapService } from 'vs/workbench/contrib/notebook/browser/services/notebookKeymapServiceImpl';
102-
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
103102
import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry';
104103
import { INotebookExecutionStateService } from 'vs/workbench/contrib/notebook/common/notebookExecutionStateService';
105104
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
@@ -429,7 +428,7 @@ class CellInfoContentProvider {
429428
private _getResult(data: {
430429
notebook: URI;
431430
outputId?: string | undefined;
432-
}, cell: NotebookCellTextModel) {
431+
}, cell: ICell) {
433432
let result: { content: string; mode: ILanguageSelection } | undefined = undefined;
434433

435434
const mode = this._languageService.createById('json');
@@ -479,7 +478,7 @@ class CellInfoContentProvider {
479478

480479
if (result) {
481480
const model = this._modelService.createModel(result.content, result.mode, resource);
482-
const cellModelListener = Event.any(cell.onDidChangeOutputs, cell.onDidChangeOutputItems)(() => {
481+
const cellModelListener = Event.any(cell.onDidChangeOutputs ?? Event.None, cell.onDidChangeOutputItems ?? Event.None)(() => {
483482
const newResult = this._getResult(data, cell);
484483

485484
if (!newResult) {

src/vs/workbench/contrib/notebook/common/notebookCommon.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ import { URI, UriComponents } from 'vs/base/common/uri';
1818
import { ILineChange } from 'vs/editor/common/diff/diffComputer';
1919
import * as editorCommon from 'vs/editor/common/editorCommon';
2020
import { Command } from 'vs/editor/common/languages';
21+
import { IReadonlyTextBuffer } from 'vs/editor/common/model';
2122
import { IAccessibilityInformation } from 'vs/platform/accessibility/common/accessibility';
2223
import { RawContextKey } from 'vs/platform/contextkey/common/contextkey';
2324
import { IEditorModel } from 'vs/platform/editor/common/editor';
2425
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
2526
import { ThemeColor } from 'vs/platform/theme/common/themeService';
27+
import { UndoRedoGroup } from 'vs/platform/undoRedo/common/undoRedo';
2628
import { IRevertOptions, ISaveOptions } from 'vs/workbench/common/editor';
2729
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
2830
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
@@ -214,7 +216,10 @@ export interface ICell {
214216
outputs: ICellOutput[];
215217
metadata: NotebookCellMetadata;
216218
internalMetadata: NotebookCellInternalMetadata;
219+
getHashValue(): number;
220+
textBuffer: IReadonlyTextBuffer;
217221
onDidChangeOutputs?: Event<NotebookCellOutputsSplice>;
222+
onDidChangeOutputItems?: Event<void>;
218223
onDidChangeLanguage: Event<string>;
219224
onDidChangeMetadata: Event<void>;
220225
onDidChangeInternalMetadata: Event<CellInternalMetadataChangedEvent>;
@@ -223,10 +228,14 @@ export interface ICell {
223228
export interface INotebookTextModel {
224229
readonly viewType: string;
225230
metadata: NotebookDocumentMetadata;
231+
readonly transientOptions: TransientOptions;
226232
readonly uri: URI;
227233
readonly versionId: number;
228-
234+
readonly length: number;
229235
readonly cells: readonly ICell[];
236+
reset(cells: ICellDto2[], metadata: NotebookDocumentMetadata, transientOptions: TransientOptions): void;
237+
applyEdits(rawEdits: ICellEditOperation[], synchronous: boolean, beginSelectionState: ISelectionState | undefined, endSelectionsComputer: () => ISelectionState | undefined, undoRedoGroup: UndoRedoGroup | undefined, computeUndoRedo?: boolean): boolean;
238+
onDidChangeContent: Event<NotebookTextModelChangedEvent>;
230239
onWillDispose: Event<void>;
231240
}
232241

src/vs/workbench/contrib/notebook/test/browser/notebookDiff.test.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ import { Mimes } from 'vs/base/common/mime';
1010
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
1111
import { NotebookDiffEditorEventDispatcher } from 'vs/workbench/contrib/notebook/browser/diff/eventDispatcher';
1212
import { NotebookTextDiffEditor } from 'vs/workbench/contrib/notebook/browser/diff/notebookTextDiffEditor';
13-
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
14-
import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';
13+
import { CellKind, INotebookTextModel } from 'vs/workbench/contrib/notebook/common/notebookCommon';
1514
import { withTestNotebookDiffModel } from 'vs/workbench/contrib/notebook/test/browser/testNotebookEditor';
1615

1716
class CellSequence implements ISequence {
1817

19-
constructor(readonly textModel: NotebookTextModel) {
18+
constructor(readonly textModel: INotebookTextModel) {
2019
}
2120

2221
getElements(): string[] | number[] | Int32Array {

src/vs/workbench/contrib/notebook/test/browser/testNotebookEditor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export class NotebookEditorTestModel extends EditorModel implements INotebookEdi
9393
return this._notebook.uri;
9494
}
9595

96-
get notebook() {
96+
get notebook(): NotebookTextModel {
9797
return this._notebook;
9898
}
9999

0 commit comments

Comments
 (0)