提交 5dc851f3 编写于 作者: R rebornix

Fix #101378. De-ref text model from celltextmodel when it's disposed.

上级 d65996f4
......@@ -21,6 +21,7 @@ import { IRelativePattern } from 'vs/base/common/glob';
import { ExtensionIdentifier } from 'vs/platform/extensions/common/extensions';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IUndoRedoService, UndoRedoElementType } from 'vs/platform/undoRedo/common/undoRedo';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
export class MainThreadNotebookDocument extends Disposable {
private _textModel: NotebookTextModel;
......@@ -36,12 +37,13 @@ export class MainThreadNotebookDocument extends Disposable {
public supportBackup: boolean,
public uri: URI,
@INotebookService readonly notebookService: INotebookService,
@IUndoRedoService readonly undoRedoService: IUndoRedoService
@IUndoRedoService readonly undoRedoService: IUndoRedoService,
@ITextModelService modelService: ITextModelService
) {
super();
this._textModel = new NotebookTextModel(handle, viewType, supportBackup, uri, undoRedoService);
this._textModel = new NotebookTextModel(handle, viewType, supportBackup, uri, undoRedoService, modelService);
this._register(this._textModel.onDidModelChangeProxy(e => {
this._proxy.$acceptModelChanged(this.uri, e);
this._proxy.$acceptEditorPropertiesChanged(uri, { selections: { selections: this._textModel.selections }, metadata: null });
......
......@@ -7,7 +7,6 @@ import { Emitter, Event } from 'vs/base/common/event';
import * as UUID from 'vs/base/common/uuid';
import * as editorCommon from 'vs/editor/common/editorCommon';
import * as model from 'vs/editor/common/model';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { PrefixSumComputer } from 'vs/editor/common/viewModel/prefixSumComputer';
import { BOTTOM_CELL_TOOLBAR_HEIGHT, CELL_MARGIN, CELL_RUN_GUTTER, CELL_STATUSBAR_HEIGHT, EDITOR_BOTTOM_PADDING, EDITOR_TOOLBAR_HEIGHT, EDITOR_TOP_MARGIN, EDITOR_TOP_PADDING, CELL_BOTTOM_MARGIN, CODE_CELL_LEFT_MARGIN } from 'vs/workbench/contrib/notebook/browser/constants';
import { CellEditState, CellFindMatch, CodeCellLayoutChangeEvent, CodeCellLayoutInfo, ICellViewModel, NotebookLayoutInfo } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
......@@ -69,8 +68,7 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
readonly viewType: string,
readonly model: NotebookCellTextModel,
initialNotebookLayoutInfo: NotebookLayoutInfo | null,
readonly eventDispatcher: NotebookEventDispatcher,
@ITextModelService private readonly _modelService: ITextModelService,
readonly eventDispatcher: NotebookEventDispatcher
) {
super(viewType, model, UUID.generateUuid());
this._register(this.model.onDidChangeOutputs((splices) => {
......@@ -174,7 +172,7 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
*/
async resolveTextModel(): Promise<model.ITextModel> {
if (!this.textModel) {
const ref = await this._modelService.createModelReference(this.model.uri);
const ref = await this.model.resolveTextModelRef();
this.textModel = ref.object.textEditorModel;
this._register(ref);
this._register(this.textModel.onDidChangeContent(() => {
......@@ -257,4 +255,8 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
matches
};
}
dispose() {
super.dispose();
}
}
......@@ -7,7 +7,6 @@ import { Emitter, Event } from 'vs/base/common/event';
import * as UUID from 'vs/base/common/uuid';
import * as editorCommon from 'vs/editor/common/editorCommon';
import * as model from 'vs/editor/common/model';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { BOTTOM_CELL_TOOLBAR_HEIGHT, CELL_MARGIN, CELL_RUN_GUTTER, CELL_STATUSBAR_HEIGHT } from 'vs/workbench/contrib/notebook/browser/constants';
import { CellFindMatch, ICellViewModel, MarkdownCellLayoutChangeEvent, MarkdownCellLayoutInfo, NotebookLayoutInfo } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { MarkdownRenderer } from 'vs/workbench/contrib/notebook/browser/view/renderers/mdRenderer';
......@@ -65,8 +64,8 @@ export class MarkdownCellViewModel extends BaseCellViewModel implements ICellVie
initialNotebookLayoutInfo: NotebookLayoutInfo | null,
readonly foldingDelegate: EditorFoldingStateDelegate,
readonly eventDispatcher: NotebookEventDispatcher,
private readonly _mdRenderer: MarkdownRenderer,
@ITextModelService private readonly _modelService: ITextModelService) {
private readonly _mdRenderer: MarkdownRenderer
) {
super(viewType, model, UUID.generateUuid());
this._layoutInfo = {
......@@ -148,7 +147,7 @@ export class MarkdownCellViewModel extends BaseCellViewModel implements ICellVie
async resolveTextModel(): Promise<model.ITextModel> {
if (!this.textModel) {
const ref = await this._modelService.createModelReference(this.model.uri);
const ref = await this.model.resolveTextModelRef();
this.textModel = ref.object.textEditorModel;
this._register(ref);
this._register(this.textModel.onDidChangeContent(() => {
......
......@@ -10,6 +10,7 @@ import { URI } from 'vs/base/common/uri';
import * as model from 'vs/editor/common/model';
import { Range } from 'vs/editor/common/core/range';
import { Disposable } from 'vs/base/common/lifecycle';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
export class NotebookCellTextModel extends Disposable implements ICell {
private _onDidChangeOutputs = new Emitter<NotebookCellOutputsSplice[]>();
......@@ -86,7 +87,8 @@ export class NotebookCellTextModel extends Disposable implements ICell {
private _language: string,
public cellKind: CellKind,
outputs: IProcessedOutput[],
metadata: NotebookCellMetadata | undefined
metadata: NotebookCellMetadata | undefined,
private readonly _modelService: ITextModelService
) {
super();
this._outputs = outputs;
......@@ -139,4 +141,17 @@ export class NotebookCellTextModel extends Disposable implements ICell {
}
};
}
async resolveTextModelRef() {
const ref = await this._modelService.createModelReference(this.uri);
ref.object.textEditorModel.onWillDispose(() => {
this.textModel = undefined;
});
return ref;
}
dispose() {
super.dispose();
}
}
......@@ -11,6 +11,7 @@ import { INotebookTextModel, NotebookCellOutputsSplice, NotebookCellTextModelSpl
import { ITextSnapshot } from 'vs/editor/common/model';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
import { InsertCellEdit, DeleteCellEdit, MoveCellEdit, SpliceCellsEdit } from 'vs/workbench/contrib/notebook/common/model/cellEdit';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
function compareRangesUsingEnds(a: [number, number], b: [number, number]): number {
if (a[1] === b[1]) {
......@@ -115,7 +116,8 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
public viewType: string,
public supportBackup: boolean,
public uri: URI,
private _undoService: IUndoRedoService
private _undoService: IUndoRedoService,
private _modelService: ITextModelService
) {
super();
this.cells = [];
......@@ -141,7 +143,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
) {
const cellHandle = this._cellhandlePool++;
const cellUri = CellUri.generate(this.uri, cellHandle);
return new NotebookCellTextModel(cellUri, cellHandle, source, language, cellKind, outputs || [], metadata);
return new NotebookCellTextModel(cellUri, cellHandle, source, language, cellKind, outputs || [], metadata, this._modelService);
}
initialize(cells: ICellDto2[]) {
......@@ -151,7 +153,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
const mainCells = cells.map(cell => {
const cellHandle = this._cellhandlePool++;
const cellUri = CellUri.generate(this.uri, cellHandle);
return new NotebookCellTextModel(cellUri, cellHandle, cell.source, cell.language, cell.cellKind, cell.outputs || [], cell.metadata);
return new NotebookCellTextModel(cellUri, cellHandle, cell.source, cell.language, cell.cellKind, cell.outputs || [], cell.metadata, this._modelService);
});
this._isUntitled = false;
......@@ -215,7 +217,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
const mainCells = insertEdit.cells.map(cell => {
const cellHandle = this._cellhandlePool++;
const cellUri = CellUri.generate(this.uri, cellHandle);
return new NotebookCellTextModel(cellUri, cellHandle, cell.source, cell.language, cell.cellKind, cell.outputs || [], cell.metadata);
return new NotebookCellTextModel(cellUri, cellHandle, cell.source, cell.language, cell.cellKind, cell.outputs || [], cell.metadata, this._modelService);
});
this.insertNewCell(insertEdit.index, mainCells, false);
break;
......@@ -583,6 +585,7 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
dispose() {
this._onWillDispose.fire();
this._cellListeners.forEach(val => val.dispose());
this.cells.forEach(cell => cell.dispose());
super.dispose();
}
}
......@@ -148,6 +148,7 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
const notebook = await this._notebookService.createNotebookFromBackup(this.viewType!, this.resource, data.metadata, data.languages, data.cells, editorId);
this._notebook = notebook!;
this._register(this._notebook);
this._name = basename(this._notebook!.uri);
......@@ -167,6 +168,7 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
private async loadFromProvider(forceReloadFromDisk: boolean, editorId: string | undefined, backupId: string | undefined) {
const notebook = await this._notebookService.resolveNotebook(this.viewType!, this.resource, forceReloadFromDisk, editorId, backupId);
this._notebook = notebook!;
this._register(this._notebook);
this._name = basename(this._notebook!.uri);
......@@ -210,4 +212,8 @@ export class NotebookEditorModel extends EditorModel implements IWorkingCopy, IN
this._notebook.setDirty(false);
return true;
}
dispose() {
super.dispose();
}
}
......@@ -5,10 +5,14 @@
import * as assert from 'assert';
import { NOTEBOOK_DISPLAY_ORDER, sortMimeTypes, CellKind, diff, CellUri } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { TestCell } from 'vs/workbench/contrib/notebook/test/testNotebookEditor';
import { TestCell, setupInstantiationService } from 'vs/workbench/contrib/notebook/test/testNotebookEditor';
import { URI } from 'vs/base/common/uri';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
suite('NotebookCommon', () => {
const instantiationService = setupInstantiationService();
const textModelService = instantiationService.get(ITextModelService);
test('sortMimeTypes default orders', function () {
const defaultDisplayOrder = NOTEBOOK_DISPLAY_ORDER;
......@@ -265,7 +269,7 @@ suite('NotebookCommon', () => {
for (let i = 0; i < 5; i++) {
cells.push(
new TestCell('notebook', i, [`var a = ${i};`], 'javascript', CellKind.Code, [])
new TestCell('notebook', i, [`var a = ${i};`], 'javascript', CellKind.Code, [], textModelService)
);
}
......@@ -291,8 +295,8 @@ suite('NotebookCommon', () => {
]
);
const cellA = new TestCell('notebook', 6, ['var a = 6;'], 'javascript', CellKind.Code, []);
const cellB = new TestCell('notebook', 7, ['var a = 7;'], 'javascript', CellKind.Code, []);
const cellA = new TestCell('notebook', 6, ['var a = 6;'], 'javascript', CellKind.Code, [], textModelService);
const cellB = new TestCell('notebook', 7, ['var a = 7;'], 'javascript', CellKind.Code, [], textModelService);
const modifiedCells = [
cells[0],
......
......@@ -4,14 +4,15 @@
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { CellKind, CellEditType } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { withTestNotebook, TestCell } from 'vs/workbench/contrib/notebook/test/testNotebookEditor';
import { withTestNotebook, TestCell, setupInstantiationService } from 'vs/workbench/contrib/notebook/test/testNotebookEditor';
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
suite('NotebookTextModel', () => {
const instantiationService = new TestInstantiationService();
const instantiationService = setupInstantiationService();
const textModelService = instantiationService.get(ITextModelService);
const blukEditService = instantiationService.get(IBulkEditService);
const undoRedoService = instantiationService.stub(IUndoRedoService, () => { });
instantiationService.spy(IUndoRedoService, 'pushElement');
......@@ -29,8 +30,8 @@ suite('NotebookTextModel', () => {
],
(editor, viewModel, textModel) => {
textModel.$applyEdit(textModel.versionId, [
{ editType: CellEditType.Insert, index: 1, cells: [new TestCell(viewModel.viewType, 5, ['var e = 5;'], 'javascript', CellKind.Code, [])] },
{ editType: CellEditType.Insert, index: 3, cells: [new TestCell(viewModel.viewType, 6, ['var f = 6;'], 'javascript', CellKind.Code, [])] },
{ editType: CellEditType.Insert, index: 1, cells: [new TestCell(viewModel.viewType, 5, ['var e = 5;'], 'javascript', CellKind.Code, [], textModelService)] },
{ editType: CellEditType.Insert, index: 3, cells: [new TestCell(viewModel.viewType, 6, ['var f = 6;'], 'javascript', CellKind.Code, [], textModelService)] },
], true, true);
assert.equal(textModel.cells.length, 6);
......@@ -54,8 +55,8 @@ suite('NotebookTextModel', () => {
],
(editor, viewModel, textModel) => {
textModel.$applyEdit(textModel.versionId, [
{ editType: CellEditType.Insert, index: 1, cells: [new TestCell(viewModel.viewType, 5, ['var e = 5;'], 'javascript', CellKind.Code, [])] },
{ editType: CellEditType.Insert, index: 1, cells: [new TestCell(viewModel.viewType, 6, ['var f = 6;'], 'javascript', CellKind.Code, [])] },
{ editType: CellEditType.Insert, index: 1, cells: [new TestCell(viewModel.viewType, 5, ['var e = 5;'], 'javascript', CellKind.Code, [], textModelService)] },
{ editType: CellEditType.Insert, index: 1, cells: [new TestCell(viewModel.viewType, 6, ['var f = 6;'], 'javascript', CellKind.Code, [], textModelService)] },
], true, true);
assert.equal(textModel.cells.length, 6);
......@@ -103,7 +104,7 @@ suite('NotebookTextModel', () => {
(editor, viewModel, textModel) => {
textModel.$applyEdit(textModel.versionId, [
{ editType: CellEditType.Delete, index: 1, count: 1 },
{ editType: CellEditType.Insert, index: 3, cells: [new TestCell(viewModel.viewType, 5, ['var e = 5;'], 'javascript', CellKind.Code, [])] },
{ editType: CellEditType.Insert, index: 3, cells: [new TestCell(viewModel.viewType, 5, ['var e = 5;'], 'javascript', CellKind.Code, [], textModelService)] },
], true, true);
assert.equal(textModel.cells.length, 4);
......@@ -128,7 +129,7 @@ suite('NotebookTextModel', () => {
(editor, viewModel, textModel) => {
textModel.$applyEdit(textModel.versionId, [
{ editType: CellEditType.Delete, index: 1, count: 1 },
{ editType: CellEditType.Insert, index: 1, cells: [new TestCell(viewModel.viewType, 5, ['var e = 5;'], 'javascript', CellKind.Code, [])] },
{ editType: CellEditType.Insert, index: 1, cells: [new TestCell(viewModel.viewType, 5, ['var e = 5;'], 'javascript', CellKind.Code, [], textModelService)] },
], true, true);
assert.equal(textModel.cells.length, 4);
......
......@@ -5,25 +5,25 @@
import * as assert from 'assert';
import { URI } from 'vs/base/common/uri';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { NotebookViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
import { CellKind, NotebookCellMetadata, diff } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { withTestNotebook, TestCell, NotebookEditorTestModel } from 'vs/workbench/contrib/notebook/test/testNotebookEditor';
import { withTestNotebook, TestCell, NotebookEditorTestModel, setupInstantiationService } from 'vs/workbench/contrib/notebook/test/testNotebookEditor';
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { NotebookEventDispatcher } from 'vs/workbench/contrib/notebook/browser/viewModel/eventDispatcher';
import { TrackedRangeStickiness } from 'vs/editor/common/model';
import { reduceCellRanges, ICellRange } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
suite('NotebookViewModel', () => {
const instantiationService = new TestInstantiationService();
const instantiationService = setupInstantiationService();
const textModelService = instantiationService.get(ITextModelService);
const blukEditService = instantiationService.get(IBulkEditService);
const undoRedoService = instantiationService.stub(IUndoRedoService, () => { });
instantiationService.spy(IUndoRedoService, 'pushElement');
const undoRedoService = instantiationService.get(IUndoRedoService);
test('ctor', function () {
const notebook = new NotebookTextModel(0, 'notebook', false, URI.parse('test'), undoRedoService);
const notebook = new NotebookTextModel(0, 'notebook', false, URI.parse('test'), undoRedoService, textModelService);
const model = new NotebookEditorTestModel(notebook);
const eventDispatcher = new NotebookEventDispatcher();
const viewModel = new NotebookViewModel('notebook', model.notebook, eventDispatcher, null, instantiationService, blukEditService, undoRedoService);
......@@ -43,7 +43,7 @@ suite('NotebookViewModel', () => {
assert.equal(viewModel.viewCells[0].metadata?.editable, true);
assert.equal(viewModel.viewCells[1].metadata?.editable, false);
const cell = viewModel.insertCell(1, new TestCell(viewModel.viewType, 0, ['var c = 3;'], 'javascript', CellKind.Code, []), true);
const cell = viewModel.insertCell(1, new TestCell(viewModel.viewType, 0, ['var c = 3;'], 'javascript', CellKind.Code, [], textModelService), true);
assert.equal(viewModel.viewCells.length, 3);
assert.equal(viewModel.notebookDocument.cells.length, 3);
assert.equal(viewModel.getCellIndex(cell), 1);
......@@ -126,13 +126,13 @@ suite('NotebookViewModel', () => {
const lastViewCell = viewModel.viewCells[viewModel.viewCells.length - 1];
const insertIndex = viewModel.getCellIndex(firstViewCell) + 1;
const cell = viewModel.insertCell(insertIndex, new TestCell(viewModel.viewType, 3, ['var c = 3;'], 'javascript', CellKind.Code, []), true);
const cell = viewModel.insertCell(insertIndex, new TestCell(viewModel.viewType, 3, ['var c = 3;'], 'javascript', CellKind.Code, [], textModelService), true);
const addedCellIndex = viewModel.getCellIndex(cell);
viewModel.deleteCell(addedCellIndex, true);
const secondInsertIndex = viewModel.getCellIndex(lastViewCell) + 1;
const cell2 = viewModel.insertCell(secondInsertIndex, new TestCell(viewModel.viewType, 4, ['var d = 4;'], 'javascript', CellKind.Code, []), true);
const cell2 = viewModel.insertCell(secondInsertIndex, new TestCell(viewModel.viewType, 4, ['var d = 4;'], 'javascript', CellKind.Code, [], textModelService), true);
assert.equal(viewModel.viewCells.length, 3);
assert.equal(viewModel.notebookDocument.cells.length, 3);
......@@ -258,10 +258,10 @@ function getVisibleCells<T>(cells: T[], hiddenRanges: ICellRange[]) {
}
suite('NotebookViewModel Decorations', () => {
const instantiationService = new TestInstantiationService();
const instantiationService = setupInstantiationService();
const textModelService = instantiationService.get(ITextModelService);
const blukEditService = instantiationService.get(IBulkEditService);
const undoRedoService = instantiationService.stub(IUndoRedoService, () => { });
instantiationService.spy(IUndoRedoService, 'pushElement');
const undoRedoService = instantiationService.get(IUndoRedoService);
test('tracking range', function () {
withTestNotebook(
......@@ -283,7 +283,7 @@ suite('NotebookViewModel Decorations', () => {
end: 2,
});
viewModel.insertCell(0, new TestCell(viewModel.viewType, 5, ['var d = 6;'], 'javascript', CellKind.Code, []), true);
viewModel.insertCell(0, new TestCell(viewModel.viewType, 5, ['var d = 6;'], 'javascript', CellKind.Code, [], textModelService), true);
assert.deepEqual(viewModel.getTrackedRange(trackedId!), {
start: 2,
......@@ -297,7 +297,7 @@ suite('NotebookViewModel Decorations', () => {
end: 2
});
viewModel.insertCell(3, new TestCell(viewModel.viewType, 6, ['var d = 7;'], 'javascript', CellKind.Code, []), true);
viewModel.insertCell(3, new TestCell(viewModel.viewType, 6, ['var d = 7;'], 'javascript', CellKind.Code, [], textModelService), true);
assert.deepEqual(viewModel.getTrackedRange(trackedId!), {
start: 1,
......@@ -343,14 +343,14 @@ suite('NotebookViewModel Decorations', () => {
end: 3
});
viewModel.insertCell(5, new TestCell(viewModel.viewType, 8, ['var d = 9;'], 'javascript', CellKind.Code, []), true);
viewModel.insertCell(5, new TestCell(viewModel.viewType, 8, ['var d = 9;'], 'javascript', CellKind.Code, [], textModelService), true);
assert.deepEqual(viewModel.getTrackedRange(trackedId!), {
start: 1,
end: 3
});
viewModel.insertCell(4, new TestCell(viewModel.viewType, 9, ['var d = 10;'], 'javascript', CellKind.Code, []), true);
viewModel.insertCell(4, new TestCell(viewModel.viewType, 9, ['var d = 10;'], 'javascript', CellKind.Code, [], textModelService), true);
assert.deepEqual(viewModel.getTrackedRange(trackedId!), {
start: 1,
......
......@@ -10,7 +10,6 @@ import { URI } from 'vs/base/common/uri';
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
import { BareFontInfo } from 'vs/editor/common/config/fontInfo';
import { Range } from 'vs/editor/common/core/range';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
import { EditorModel } from 'vs/workbench/common/editor';
import { ICellRange, ICellViewModel, INotebookEditor, INotebookEditorContribution, INotebookEditorMouseEvent, NotebookLayoutInfo } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
......@@ -24,6 +23,16 @@ import { Webview } from 'vs/workbench/contrib/webview/browser/webview';
import { ICompositeCodeEditor, IEditor } from 'vs/editor/common/editorCommon';
import { NotImplementedError } from 'vs/base/common/errors';
import { Schemas } from 'vs/base/common/network';
import { ITextModelService } from 'vs/editor/common/services/resolverService';
import { TestInstantiationService } from 'vs/platform/instantiation/test/common/instantiationServiceMock';
import { TextModelResolverService } from 'vs/workbench/services/textmodelResolver/common/textModelResolverService';
import { IModelService } from 'vs/editor/common/services/modelService';
import { ModelServiceImpl } from 'vs/editor/common/services/modelServiceImpl';
import { UndoRedoService } from 'vs/platform/undoRedo/common/undoRedoService';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { TestThemeService } from 'vs/platform/theme/test/common/testThemeService';
export class TestCell extends NotebookCellTextModel {
constructor(
......@@ -32,9 +41,10 @@ export class TestCell extends NotebookCellTextModel {
public source: string[],
language: string,
cellKind: CellKind,
outputs: IProcessedOutput[]
outputs: IProcessedOutput[],
modelService: ITextModelService
) {
super(CellUri.generate(URI.parse('test:///fake/notebook'), handle), handle, source, language, cellKind, outputs, undefined);
super(CellUri.generate(URI.parse('test:///fake/notebook'), handle), handle, source, language, cellKind, outputs, undefined, modelService);
}
}
......@@ -317,12 +327,26 @@ export class NotebookEditorTestModel extends EditorModel implements INotebookEdi
}
}
export function withTestNotebook(instantiationService: IInstantiationService, blukEditService: IBulkEditService, undoRedoService: IUndoRedoService, cells: [string[], string, CellKind, IProcessedOutput[], NotebookCellMetadata][], callback: (editor: TestNotebookEditor, viewModel: NotebookViewModel, textModel: NotebookTextModel) => void) {
export function setupInstantiationService() {
const instantiationService = new TestInstantiationService();
instantiationService.stub(IUndoRedoService, instantiationService.createInstance(UndoRedoService));
instantiationService.stub(IConfigurationService, new TestConfigurationService());
instantiationService.stub(IThemeService, new TestThemeService());
instantiationService.stub(IModelService, instantiationService.createInstance(ModelServiceImpl));
instantiationService.stub(ITextModelService, <ITextModelService>instantiationService.createInstance(TextModelResolverService));
return instantiationService;
}
export function withTestNotebook(instantiationService: TestInstantiationService, blukEditService: IBulkEditService, undoRedoService: IUndoRedoService, cells: [string[], string, CellKind, IProcessedOutput[], NotebookCellMetadata][], callback: (editor: TestNotebookEditor, viewModel: NotebookViewModel, textModel: NotebookTextModel) => void) {
const textModelService = instantiationService.get(ITextModelService);
const viewType = 'notebook';
const editor = new TestNotebookEditor();
const notebook = new NotebookTextModel(0, viewType, false, URI.parse('test'), undoRedoService);
const notebook = new NotebookTextModel(0, viewType, false, URI.parse('test'), undoRedoService, textModelService);
notebook.cells = cells.map((cell, index) => {
return new NotebookCellTextModel(notebook.uri, index, cell[0], cell[1], cell[2], cell[3], cell[4]);
return new NotebookCellTextModel(notebook.uri, index, cell[0], cell[1], cell[2], cell[3], cell[4], textModelService);
});
const model = new NotebookEditorTestModel(notebook);
const eventDispatcher = new NotebookEventDispatcher();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册