testNotebookEditor.ts 8.6 KB
Newer Older
1 2 3 4 5 6 7
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { URI } from 'vs/base/common/uri';
import { PieceTreeTextBufferFactory } from 'vs/editor/common/model/pieceTreeTextBuffer/pieceTreeTextBufferBuilder';
R
rebornix 已提交
8
import { CellKind, IOutput, CellUri, NotebookCellMetadata } from 'vs/workbench/contrib/notebook/common/notebookCommon';
R
rebornix 已提交
9
import { NotebookViewModel, IModelDecorationsChangeAccessor, CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookViewModel';
10 11
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { NotebookEditorModel } from 'vs/workbench/contrib/notebook/browser/notebookEditorInput';
R
rebornix 已提交
12
import { INotebookEditor, NotebookLayoutInfo, ICellViewModel, ICellRange, INotebookEditorMouseEvent, INotebookEditorContribution } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
13
import { IMouseWheelEvent } from 'vs/base/browser/mouseEvent';
R
rebornix 已提交
14
import { OutputRenderer } from 'vs/workbench/contrib/notebook/browser/view/output/outputRenderer';
15
import { BareFontInfo } from 'vs/editor/common/config/fontInfo';
R
rebornix 已提交
16
import { Range } from 'vs/editor/common/core/range';
R
rebornix 已提交
17 18
import { IBulkEditService } from 'vs/editor/browser/services/bulkEditService';
import { IUndoRedoService } from 'vs/platform/undoRedo/common/undoRedo';
19 20
import { NotebookTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookTextModel';
import { NotebookCellTextModel } from 'vs/workbench/contrib/notebook/common/model/notebookCellTextModel';
R
rebornix 已提交
21
import { NotebookEventDispatcher } from 'vs/workbench/contrib/notebook/browser/viewModel/eventDispatcher';
R
rebornix 已提交
22
import { Webview } from 'vs/workbench/contrib/webview/browser/webview';
R
rebornix 已提交
23
import { IDisposable } from 'vs/base/common/lifecycle';
R
rebornix 已提交
24
import { Emitter, Event } from 'vs/base/common/event';
25

R
rebornix 已提交
26
export class TestCell extends NotebookCellTextModel {
27 28
	constructor(
		public viewType: string,
R
rebornix 已提交
29 30 31 32
		handle: number,
		source: string[],
		language: string,
		cellKind: CellKind,
33 34
		outputs: IOutput[]
	) {
R
rebornix 已提交
35
		super(CellUri.generate(URI.parse('test:///fake/notebook'), handle), handle, source, language, cellKind, outputs, undefined);
36
	}
37 38
	contentChange(): void {
		// throw new Error('Method not implemented.');
39 40
	}

41
	resolveTextBufferFactory(): PieceTreeTextBufferFactory {
42 43 44 45 46 47
		throw new Error('Method not implemented.');
	}
}

export class TestNotebookEditor implements INotebookEditor {

R
rebornix 已提交
48 49 50 51
	get viewModel() {
		return undefined;
	}

52
	constructor(
R
rebornix 已提交
53
	) { }
R
rebornix 已提交
54 55 56
	getDomNode(): HTMLElement {
		throw new Error('Method not implemented.');
	}
R
rebornix 已提交
57 58 59 60 61 62

	private _onDidChangeModel = new Emitter<void>();
	onDidChangeModel: Event<void> = this._onDidChangeModel.event;
	getContribution<T extends INotebookEditorContribution>(id: string): T {
		throw new Error('Method not implemented.');
	}
R
rebornix 已提交
63 64 65 66 67 68
	onMouseUp(listener: (e: INotebookEditorMouseEvent) => void): IDisposable {
		throw new Error('Method not implemented.');
	}
	onMouseDown(listener: (e: INotebookEditorMouseEvent) => void): IDisposable {
		throw new Error('Method not implemented.');
	}
R
rebornix 已提交
69 70 71 72 73

	setHiddenAreas(_ranges: ICellRange[]): boolean {
		throw new Error('Method not implemented.');
	}

R
rebornix 已提交
74 75 76
	getInnerWebview(): Webview | undefined {
		throw new Error('Method not implemented.');
	}
77

78 79 80 81 82 83 84 85 86 87 88 89
	cancelNotebookCellExecution(cell: ICellViewModel): void {
		throw new Error('Method not implemented.');
	}

	executeNotebook(): Promise<void> {
		throw new Error('Method not implemented.');
	}

	cancelNotebookExecution(): void {
		throw new Error('Method not implemented.');
	}

90 91 92 93
	executeNotebookCell(cell: ICellViewModel): Promise<void> {
		throw new Error('Method not implemented.');
	}

94 95 96 97 98 99
	isNotebookEditor = true;

	postMessage(message: any): void {
		throw new Error('Method not implemented.');
	}

100 101 102 103
	setCellSelection(cell: CellViewModel, selection: Range): void {
		throw new Error('Method not implemented.');
	}

R
rebornix 已提交
104 105 106
	selectElement(cell: CellViewModel): void {
		throw new Error('Method not implemented.');
	}
R
rebornix 已提交
107

108
	moveCellDown(cell: CellViewModel): Promise<boolean> {
109 110 111
		throw new Error('Method not implemented.');
	}

112
	moveCellUp(cell: CellViewModel): Promise<boolean> {
113 114 115
		throw new Error('Method not implemented.');
	}

116
	moveCell(cell: ICellViewModel, relativeToCell: ICellViewModel, direction: 'above' | 'below'): Promise<boolean> {
117 118 119
		throw new Error('Method not implemented.');
	}

120
	setSelection(cell: CellViewModel, selection: Range): void {
R
rebornix 已提交
121 122
		throw new Error('Method not implemented.');
	}
R
rebornix 已提交
123 124 125 126 127 128 129 130 131
	revealRangeInView(cell: CellViewModel, range: Range): void {
		throw new Error('Method not implemented.');
	}
	revealRangeInCenter(cell: CellViewModel, range: Range): void {
		throw new Error('Method not implemented.');
	}
	revealRangeInCenterIfOutsideViewport(cell: CellViewModel, range: Range): void {
		throw new Error('Method not implemented.');
	}
132

R
rebornix 已提交
133 134
	revealLineInView(cell: CellViewModel, line: number): void {
		throw new Error('Method not implemented.');
R
rebornix 已提交
135 136 137
	}
	getLayoutInfo(): NotebookLayoutInfo {
		throw new Error('Method not implemented.');
R
rebornix 已提交
138 139 140 141 142 143
	}
	revealLineInCenterIfOutsideViewport(cell: CellViewModel, line: number): void {
		throw new Error('Method not implemented.');
	}
	revealLineInCenter(cell: CellViewModel, line: number): void {
		throw new Error('Method not implemented.');
R
rebornix 已提交
144 145 146 147 148 149 150 151 152 153
	}
	focus(): void {
		throw new Error('Method not implemented.');
	}
	showFind(): void {
		throw new Error('Method not implemented.');
	}
	hideFind(): void {
		throw new Error('Method not implemented.');
	}
R
rebornix 已提交
154
	revealInView(cell: CellViewModel): void {
R
rebornix 已提交
155 156
		throw new Error('Method not implemented.');
	}
R
rebornix 已提交
157
	revealInCenter(cell: CellViewModel): void {
R
rebornix 已提交
158 159
		throw new Error('Method not implemented.');
	}
R
rebornix 已提交
160
	revealInCenterIfOutsideViewport(cell: CellViewModel): void {
R
rebornix 已提交
161
		throw new Error('Method not implemented.');
162
	}
163
	insertNotebookCell(cell: CellViewModel, type: CellKind, direction: 'above' | 'below'): CellViewModel {
R
rebornix 已提交
164
		throw new Error('Method not implemented.');
165
	}
166 167
	deleteNotebookCell(cell: CellViewModel): Promise<boolean> {
		throw new Error('Method not implemented.');
168 169 170 171 172 173 174 175 176 177 178 179 180 181
	}
	editNotebookCell(cell: CellViewModel): void {
		// throw new Error('Method not implemented.');
	}
	saveNotebookCell(cell: CellViewModel): void {
		// throw new Error('Method not implemented.');
	}
	focusNotebookCell(cell: CellViewModel, focusEditor: boolean): void {
		// throw new Error('Method not implemented.');
	}
	getActiveCell(): CellViewModel | undefined {
		// throw new Error('Method not implemented.');
		return;
	}
R
rebornix 已提交
182
	async layoutNotebookCell(cell: CellViewModel, height: number): Promise<void> {
183
		// throw new Error('Method not implemented.');
R
rebornix 已提交
184
		return;
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202
	}
	createInset(cell: CellViewModel, output: IOutput, shadowContent: string, offset: number): void {
		// throw new Error('Method not implemented.');
	}
	removeInset(output: IOutput): void {
		// throw new Error('Method not implemented.');
	}
	triggerScroll(event: IMouseWheelEvent): void {
		// throw new Error('Method not implemented.');
	}
	getFontInfo(): BareFontInfo | undefined {
		return BareFontInfo.createFromRawSettings({
			fontFamily: 'Monaco',
		}, 1, true);
	}
	getOutputRenderer(): OutputRenderer {
		throw new Error('Method not implemented.');
	}
R
rebornix 已提交
203 204 205 206

	changeDecorations(callback: (changeAccessor: IModelDecorationsChangeAccessor) => any): any {
		throw new Error('Method not implemented.');
	}
207 208
}

R
rebornix 已提交
209 210 211 212
// export function createTestCellViewModel(instantiationService: IInstantiationService, viewType: string, notebookHandle: number, cellhandle: number, source: string[], language: string, cellKind: CellKind, outputs: IOutput[]) {
// 	const mockCell = new TestCell(viewType, cellhandle, source, language, cellKind, outputs);
// 	return createCellViewModel(instantiationService, viewType, notebookHandle, mockCell);
// }
213

214
export function withTestNotebook(instantiationService: IInstantiationService, blukEditService: IBulkEditService, undoRedoService: IUndoRedoService, cells: [string[], string, CellKind, IOutput[], NotebookCellMetadata][], callback: (editor: TestNotebookEditor, viewModel: NotebookViewModel) => void) {
215
	const viewType = 'notebook';
R
rebornix 已提交
216
	const editor = new TestNotebookEditor();
217
	const notebook = new NotebookTextModel(0, viewType, URI.parse('test'));
218
	notebook.cells = cells.map((cell, index) => {
219
		return new NotebookCellTextModel(notebook.uri, index, cell[0], cell[1], cell[2], cell[3], cell[4]);
220 221
	});
	const model = new NotebookEditorModel(notebook);
R
rebornix 已提交
222
	const eventDispatcher = new NotebookEventDispatcher();
223
	const viewModel = new NotebookViewModel(viewType, model, eventDispatcher, null, instantiationService, blukEditService, undoRedoService);
224 225 226 227 228 229

	callback(editor, viewModel);

	viewModel.dispose();
	return;
}